Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to appendant for loop data to new coloum of a matrix
1 次查看(过去 30 天)
显示 更早的评论
Hi guys, I am having problem storing my new for loop data to a new column of my matrix. For each C value, there should be a set of B values with all A values. I want to store each set of B values to new column in MAB. My current codes overwrite the column:
s=0;
g=0;
for C = 1:0.1:5;
for A = -10:1:10;
B = pi*A*C;
MAB(s+1,1) = A;
MAB(s+1,2) = B;
s = s+1;
end
s = 0;
plot(MAB(:,1),MAB(:,2))
MAC(g+1,1) = C;
MAC(g+1,2) = B;
g = g+1;
end
g=0;
figure
plot(MAC(:,1),MAC(:,2))
Please let me know what I can do. Thanks heaps!
0 个评论
回答(1 个)
KSSV
2017-2-22
C = 1:0.1:5 ;
A = -10:1:10 ;
MAB = cell(length(C),length(A)) ;
MAC = cell(length(C),1) ;
for i = 1:length(C);
for j = 1:length(A)
B = pi*A(j)*C(i);
MAB{i,j}(j,1) = A(j);
MAB{i,j}(j,2) = B;
end
MAC{i}(i,1) = C(i);
MAC{i}(i,2) = B;
end
NOw MAB, MAC are cells. You can access them.
1 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!