how to add ; in real time matrix in matlab?

조회 수: 2 (최근 30일)
Mudasir Ahmed
Mudasir Ahmed 2015년 12월 30일
댓글: Mudasir Ahmed 2016년 1월 1일
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

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 30일
편집: Walter Roberson 2015년 12월 30일
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];

추가 답변 (1개)

Guillaume
Guillaume 2015년 12월 30일
편집: Guillaume 2015년 12월 30일
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
Walter Roberson
Walter Roberson 2016년 1월 1일
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
Mudasir Ahmed
Mudasir Ahmed 2016년 1월 1일
Thank you so much sir :)

댓글을 달려면 로그인하십시오.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by