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!