Generate a character matrix through indexing and a for loop
1 次查看(过去 30 天)
显示 更早的评论
I want to generate a character matrix through indexing and a for loop. This is what I have so far:
top3Table = ones(3,1); %set row dimension
for i = 1:3
Col1= city(top3Pairs(i,1),:);
Col2= city(top3Pairs(i,2),:);
Row = [Col1,Col2];
top3Table(i) = Row
end
city is a character matrix. An example of one of it's entries is 'Manila'.
The following error occurs: In an assignment A(:) = B, the number of elements in A and B must be the same.
I understand why this error is happening but I'm not sure how to fix it. Please advise!
0 个评论
回答(1 个)
Azzi Abdelmalek
2016-5-2
编辑:Azzi Abdelmalek
2016-5-2
top3Table(i,1:2) = Row
To pre-allocate your matrix:
top3Table = ones(3,2)
另请参阅
类别
在 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!