Assign values to empty matrix
5 views (last 30 days)
Show older comments
Mridul Garg
on 17 Jul 2016
Commented: Mridul Garg
on 17 Jul 2016
Hello
I want to create an empty matrix of unknown rows and known columns, then run a loop and assign values to it iteratively. So for example, my code should be something like-
result=zeros(10,3);
for i=1:10
num=1;file=i;
result(i,1)=strcat(num,'_',file);
result(i,2)=tp; % result of some calculation
result(i,3)=delay; % result of another calculation;
end;
Matrices in matlab cannot have both string and numeric types, so how do I proceed doing this?
Thanks in advance!
0 Comments
Accepted Answer
Azzi Abdelmalek
on 17 Jul 2016
Edited: Azzi Abdelmalek
on 17 Jul 2016
You can use cell arrays
A={1 2 'abc' 'efg' [1 2;3 4] [] ''}
Remarque: result=zeros(10,3); is not an empty matrix. With cell arrays you cen write:
result=cell(10,3)
for i=1:10
num=1;
file=i;
result{i,1}=sprintf('%d_%d',num,file);
tp=rand;
delay=rand;
result{i,2}=tp; % result of some calculation
result{i,3}=delay; % result of another calculation;
end;
result
2 Comments
More Answers (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!