how to add ; in real time matrix in matlab?

hi
i have a matrix of 1000 by 3. which i have to copy from some where and paste in the matlab. But as the matrix is classified as 100 by 3, so i have to add ; after every 3rd element. which is very much time consuming for considering that size of array. is there any method in matlab which print ; after every 3rd element. in the end i copy all array and past in my code. kindly help me :)
with best regards mudasir ahmed

 Accepted Answer

In MATLAB when you are inside [], then end of line is treated as a semi-colon (unless the line ended with ... )
A = [1 2 3
4 5 6
7 8 9];
This is the same as
A = [1 2 3; ...
4 5 6; ...
7 8 9];

More Answers (1)

Guillaume
Guillaume on 30 Dec 2015
Edited: Guillaume on 30 Dec 2015
Assuming you meant that the original matrix is 100x30 (not 100x3 which makes no sense), you could simply paste it as is and reshape afterwards:
m = reshape(m', 3, 1000)'

5 Comments

Thank you so much sir :)
Sir, i have a matrix of 1000 by 3. and i want use sym instruction for each element of that array then what should i do: means how i easily program it without any manual effort.
like
[sym('1.23232323232354542323232') sym('2.5656565656565656566565') sym('4.56565656565665655656656') ;
sym('1.23232323232354542323232') sym('2.5656565656565656566565') sym('4.56565656565665655656656')
...;
...;
...]
with best regards mudasir ahmed
Store the values in a text file. cellfun(@sym) the text.
fid = fopen('YourFile.txt', 'rt');
datacell = textscan(fid, '%s%s%s', 'CollectOutput', 1);
fclose(fid);
M = cellfun(@sym, horzcat(datacell{:}));
Dear Sir
i have written the following code for text file attached in this email. the first three lines execute correctly and gives data cell dimensions 13 by 3. as i take short matrix for learning and in the text file matrix size is 13 by 3. but last line generates error which i pasted in last.
fid = fopen('C:\Users\Mudasir Ahmed\Desktop\farhan.txt', 'rt')
datacell = textscan(fid, '%s %s %s', 'CollectOutput', 1)
fclose(fid)
M = cellfun(@sym, horzcat(datacell{:}))
in above code. by executing last line, matlab gives following error:
Error using sym>convertExpression (line 1362) Conversion to 'sym' returned the MuPAD error: Error: Invalid input. 'expression' is expected. [line 1, col 52]
Error in sym>convertChar (line 1273)
s = convertExpression(x);
Error in sym>convertCharWithOption (line 1256)
s = convertChar(x);
Error in sym>tomupad (line 984)
S = convertCharWithOption(x,a);
Error in sym (line 139)
S.s = tomupad(x,'');
with best regards
mudasir ahmed
fid = fopen('C:\Users\Mudasir Ahmed\Desktop\farhan.txt', 'rt')
datacell = textscan(fid, '%s %s %s', 'CollectOutput', 1, 'Delimiter', ',');
fclose(fid);
data = datacell{1};
M = sym(zeros(size(data));
for K = 1 : numel(data);M(K) = sym(data{K}); end
Thank you so much sir :)

Sign in to comment.

Products

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!