How to iteratively append elements to an array
이전 댓글 표시
I = imread(chart_image);
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
N= zeros(24,3);
final_chart =zeros (24,3);
Vals = [175 175; 425 175; 650 175; 925 175;
175 420; 425 420; 650 420; 925 420;
175 670; 425 670; 650 670 ; 925 670 ;
175 925; 425 925; 650 925; 925 925;
175 1170; 425 1170; 650 1170; 925 1170;
175 1425; 425 1425 ; 650 1425 ; 925 1425];
for i = 1:24
N(i)=[R(Vals(i,1),Vals(i,2)) G(Vals(i,1),Vals(i,2)) B(Vals(i,1),Vals(i,2))];
final_chart % the variable I want to modify to be able to store the vales of all N as it iterates over the 24 values in Vals into a single 24x3 matrix
end
hello, I wanted to add the value of each N to a final array called final_chart, but I keep getting error "Unable to perform assignment because the left and right sides have a different number of elements.", I've tried other ways to append but for some reason I keep failing all of those. Can someone help me understand where I'm going wrong and help me fix my code. Thank you.
댓글 수: 2
Guillaume
2019년 4월 9일
I don't see how you can get the error "Unable to perform assignment because the left and right sides have a different number of elements" from the code you've posted, since there's no indexing on the left-hand side of any the assignment lines. This error would only occur if you'd written
N(i, :) = ...
%not N(i) = ...
It's not clear what you're trying to do. Your current code overwrites N at each step, so only the value calculated on the last step is retained.
Abdul Rahim Mohammad
2019년 4월 9일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!