How to deal with dimension of the both sides?
Show older comments
Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side.
X1_bar_i =[9.59547499999917
58282.181075
35.4837749999997
58288.903275
-35.4750250000006
58455.670975
-9.60422500000095
58462.389975]
X2_bar_i =[9.59557499999937
58282.183075
35.4903749999994
58288.908875
-35.4809250000008
58455.676575
-9.60502500000075
58462.394475]
for i=1:size(X1_bar_i)
H(i,1)= [0 X1_bar_i(i+1,1) X1_bar_i(i,1) -X1_bar_i(i+1,1) 0 1;X1_bar_i(i+1,1) X1_bar_i(i,1) 0 X1_bar_i(i,1) 1 0];
i=i+1;
end
The dimension of the H should be 2*6. How can I do it?
2 Comments
Nikhil Sapre
on 2 Jul 2021
Can you explain what do you mean by the dimension of the H should be 2*6? Why?
How is H formed? Can you elaborate with a simple example?
Scott MacKenzie
on 2 Jul 2021
In MATLAB, the loop index variable in a for-loop cannot be changed via code in the loop. So, the line
i = i + 1;
has no bearing on the value of the variable i as used in the loop.
Other issues... X1_bar_i is a vector, not a matrix. Accessing elements require one index, not two.
Also, accessing the element in position i+1 of X1_bar_i is not possible in the last iteration when i is equal to the length of the vector. That is an attempt to access the element past the end of the vector, which is not possible.
So, there are a few issues to think about here. Good luck.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!