Improper assignment with rectangular empty matrix ERROR!

I ran this small code to get the indices for the matching values of b in matrix A. The output throws an error.
a = [1 2 3 4];
b = [2 3 4 5];
for i = 1:length(b)
c(i) = find(a == b(i));
end
% ---------------- OUTPUT --------------- %
Improper assignment with rectangular empty matrix.
Error in IndicesOfcomputedValues (line 5)
c(i) = find(a == b(i));

 채택된 답변

madhan ravi
madhan ravi 2018년 10월 19일
편집: madhan ravi 2018년 10월 19일
[idx,values] = ismember(b,a) %returns values and logical index of b in a
index=find(ismember(b,a)) returns linear index of b in a

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2018년 10월 19일

편집:

2018년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by