Problem on storing data in new table using for loop

1 次查看(过去 30 天)
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

回答(1 个)

KSSV
KSSV 2021-2-1
编辑:KSSV 2021-2-1
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 个评论
Yen Su
Yen Su 2021-2-1
But my for loop for column begin from column 12 not from 1. I see your code staring from column 1. Please advice.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by