??? In an assignment A(I) = B, the number of elements in B and I must be the same. matlab error
1 次查看(过去 30 天)
显示 更早的评论
I have problem with indexing
my code is:
function [d] = tazisko6(A)
d1=length(A); d2 =length(A{1});
s=0;
for i=1:d1
for j=1:d2
s=s+(A{i}{j});
end
if d2~=1
d=s/2;
else
d=s;
end
end
[t1,t2]=size(Z)%cell 1x3 cell
for i=1:t2 [d]=tazisko6(Z(i))
end
ouput: d=2.8000 3.6000 17.2000
d= 27.7500 35.3500 50.3000
d =
2.4000 3.5500 17.7500
i want to have ouput in the form d(1)= 2.8000 3.6000 17.2000 d(2)= 2.8000 3.6000 17.2000 d3(3)= 2.4000 3.5500 17.7500
when I add to the source code variables i
for i=1:t2 [d(i)]=tazisko6(Z(i))
end
matlab error ??? In an assignment A(I) = B, the number of elements in B and I must be the same
Can you help me with indexing ?
Thanks
2 个评论
Image Analyst
2013-11-2
You forgot to give the error message. Don't snip or paraphrase. Copy and paste ALL THE RED TEXT so we can tell what is going on. And I don't understand this "when I add to the source code variables i
for i=1:t2 [d(i)]=tazisko6(Z(i))
end"
You're not adding anything to i - it's the same as the first time you do that, and anyway, you're not adding anything to i, you're specifying that it take on a sequence of numbers: 1, 2, 3, 4, ...t2. So I don't see what you did differently in that chunk of code that is different than the first time you called it when it worked and you got d as an output.
回答(2 个)
Tomas
2013-11-2
1 个评论
Image Analyst
2013-11-2
It is not complete (full). I get this when I try to run it:
Undefined function 'euklid6' for input arguments of type 'double'.
Error in test3 (line 28)
Z1(j)= euklid6(TAZ(j,:),B);%euklidovska vzdialenost
You did not supply euklid6() and you didn't tell us what number or letters to input at the input prompt. Please make it easy to help you, not hard . http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!