Error - ??? Improper assignment with rectangular empty matrix - using "for"
显示 更早的评论
Hello,
I am attempting to run a script through several loops. However I keep receiving an error message no matter what I do to try and fix it. Please see below:
A=[1 3 4 2 5];
B=[1 2 3 4 5];
n=length(A);
Ind=ones(1,n);
for i=1:n
Ind(i)=find(A<=min(B));
A(Ind(i))=Inf;
end
Ind
Essentially I want to fill in the array "Ind" with the indices relating A and B. If successful the output from this particular code should be Ind=[1 4 2 3 5]. Unfortunately this error keeps appearing no matter what I try "??? Improper assignment with rectangular empty matrix." I would appreciate any assistance you could provide.
Thanks!
1 个评论
Oleg Komarov
2011-2-18
Not clear what you want, what are you actually trying to do?
采纳的回答
更多回答(1 个)
Robert Cumming
2011-2-18
0 个投票
Have you tried stepping through your code in debug mode?
Objective: You want to find where each B is located in A - correct?
So for each B (not the min) find where it is in A, i.e.
find(A==B(i));
You should do checks to make sure you dont have duplicates (As that will fail in the above case)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!