필터 지우기
필터 지우기

Generate a character matrix through indexing and a for loop

조회 수: 1 (최근 30일)
Mae
Mae 2016년 5월 2일
댓글: Mae 2016년 5월 2일
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!

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 2일
편집: Azzi Abdelmalek 2016년 5월 2일
top3Table(i,1:2) = Row
To pre-allocate your matrix:
top3Table = ones(3,2)
  댓글 수: 1
Mae
Mae 2016년 5월 2일
A different error pops up: Subscripted assignment dimension mismatch.
Col1 is a character value with 8 characters :/

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by