Problem on storing data in new table using for loop
1 view (last 30 days)
Show older comments
I have snippet of code shown below:
I used for loop for every row and column and store each value in new table. I create new table as Newtable=zeros(10,100). When I run this code, each value from for loop iteration, the value is saved starting at column 12. I want to start from column 1 for each value to be stored using for loop. I don't know how to solve this? Any advice is appreciated.
NewTable=zeros(10,100);
for k=1:nrow
if tarray(k,2)==1
for m=12:ncol
for n=1:nrow
NewTable(n,m)=interp1(A(3:end,1),A(3:end,2),tarray(n,m));
end
end
0 Comments
Answers (1)
KSSV
on 1 Feb 2021
Edited: KSSV
on 1 Feb 2021
NewTable=zeros(10,100);
for k=1:nrow
if tarray(k,2)==1
for m=1:ncol % <---- start from m = 1
for n=1:nrow
NewTable(n,m)=interp1(A(3:end,1),A(3:end,2),tarray(n,m));
end
end
Also the above can be achieved with:
NewTable=zeros(10,100);
for k=1:nrow
if tarray(k,2)==1
for n=1:nrow
NewTable(n,:)=interp1(A(3:end,1),A(3:end,2),tarray(n,:));
end
See Also
Categories
Find more on Loops and Conditional Statements 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!