Why isn't my For Loop working?
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am new to Matlab, and am struggling currently to write a functional For Loop.
If anyone could point me to where I am going wrong/what I'm missing, I would be so grateful!
I have 2 column vectors, containing lat and long positions. Sample below:
novLat1 novLat2
-56.63 -56.26
-56.50 -56.25
-56.43 -56.32
-56.27 -56.32
-56.17 -56.42
I need to extract the data from each row of novLat1 and novLat2 to make a new simple two-element vector variable, e.g. [-56.63 -56.26].
Here is my (very basic) code so far:
for ii = 1:length(novLat1);
Lat_longaxis_N01(ii,:) = [novLat1(ii) novLat2(ii)];
end
and the error message I am seeing:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
I have no idea why this isn't working. The error message when I hover over the code says: 'The variable Lat_longaxis_N01' appears to change size on every loop iteration. Consider preallocating for speed.'
Thanks in advance.. if I can get this working it will save me so much time as there are many, many lat and long positions to work through.
15 个评论
回答(1 个)
Jan
2021-3-12
编辑:Jan
2021-3-12
Please post a copy of the complete message. This includes the line number.
The posted code does not contain a problem which produce this error message. So I guessd boldly, that it is another part of the code. Maybe you did not save the file after editing? Or this is not the file, which is actually running? Check this using a breakpoint in the code.
By the way, there is no need for a loop:
Lat_longaxis_N01 = [novLat1, novLat2];
3 个评论
Jan
2021-3-15
The message tells you, that the problem is here:
CODE_iceberg_trajectory_create_daily_vars.m Line: 69 Column: 26
So what do you find in this line? Did you fix it already?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!