Problem on storing data in new table using for loop

1 view (last 30 days)
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

Answers (1)

KSSV
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
  1 Comment
Yen Su
Yen Su on 1 Feb 2021
But my for loop for column begin from column 12 not from 1. I see your code staring from column 1. Please advice.

Sign in to comment.

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!