storing values in matrix using for loop
3 次查看(过去 30 天)
显示 更早的评论
Hi I want to store values in a [3x3] matrix but getting error. Any help would be appreciated
for i=1:3
answerA(i,1)=1*i
answerB(i,2)=2*i
answerC(i,3)=i
% tableA=[answerA answerB answer C]
end
table=[reshape(answerA,[],1) reshape(answerB,[],1) reshape(answerC,[],1)]
% table=[reshape(answerA,[],1)]
ERROR:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in AllCurvesfit (line 80)
table=[reshape(answerA,[],1) reshape(answerB,[],1)]
0 个评论
采纳的回答
KSSV
2019-3-13
编辑:KSSV
2019-3-13
answerA = zeros(3,1) ;
answerB = zeros(3,1) ;
answerC = zeros(3,1) ;
for i=1:3
answerA(i)=1*i ;
answerB(i)=2*i ;
answerC(i)=i ;
end
table=[answerA answerB answerC]
May be you wanted:
T = table(answerA, answerB, answerC)
The above can be achieved without loops also:
i = (1:3)' ;
A = [i 2*i i]
更多回答(0 个)
另请参阅
类别
在 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!