Error using a for-loop

1 view (last 30 days)
Sam
Sam on 19 Dec 2014
Commented: Star Strider on 20 Dec 2014
The following gives an error and I don't know why. The code runs perfectly when I leave '(i_testen)' away behind 'Enkel_hoek_afg'.
for i_testen=1:5
...
Enkel_hoek_afg(i_testen) = Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))
end
Error: In an assignment A(I) = B, the number of elements in B and I must be the same.

Accepted Answer

Star Strider
Star Strider on 19 Dec 2014
See if this solves it:
for i_testen=1:5
...
Enkel_hoek_afg(i_testen,:) = Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))
end
This assumes ‘Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))’ is a row vector of constant length.
If it is not, create a cell array instead:
Enkel_hoek_afg{i_testen} = Enkel_hoek(1:Afg_c_RANK_RKNE(2,1))
Note that here, curly brackets ‘{}’ replace parentheses ‘()’ on the left-hand side of this assignment.
  6 Comments
Sam
Sam on 20 Dec 2014
Strange, when I tried it the first time it didn't work. Now I've tried it again, and it works... Well, thanks a lot!
Star Strider
Star Strider on 20 Dec 2014
My pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!