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
0 个评论
回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!