MATLAB Answers

Dimension problem in for loop?

1 view (last 30 days)
vimal kumar chawda
vimal kumar chawda on 2 Jul 2021
Answered: Cris LaPierre on 3 Jul 2021
I have problem with dimensions. Please find the whole code in attachment.
clc;
clear all;
close all;
format long g;
load('Data\data.mat')
X_1 = reshape(transpose(coord{1:4,2:3}),[8,1]);
X_2 = reshape(transpose(coord{5:8,2:3}),[8,1]);
posteriori_standard_deviation = 1.02; %in meter
displacement_vector = [X_2-X_1];
F = [1 0 1 0 1 0 1 0]%; 0 1 0 1 0 1 0 1];
n=4;
x_gravity_epoch1 = (1/n)*(F* X_1);
x_gravity_epoch2 = (1/n)*(F* X_2);
X1_bar_i = X_1 - x_gravity_epoch1';
X2_bar_i = X_2 - x_gravity_epoch2';
% x_bar_i = x_bar_i';
% y_bar_i = y_bar_i';
for i=1:size(X1_bar_i)
H(i,:)= [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 error is Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side.

Answers (1)

Cris LaPierre
Cris LaPierre on 3 Jul 2021
I believe the issue is that you are trying to assign a 2-row array into a single row of H. Hence, the dimension mismatch error. If your intent is to assign the array to 2 rows of H, then your row index must include both rows.
% Assignment to 2 rows works
A(1:2,:)=rand(2,6)
A = 2×6
0.8925 0.9049 0.9095 0.9129 0.5104 0.9256 0.1996 0.1794 0.4227 0.2812 0.9497 0.2225
% Assignment to 1 row doesn't work
A(3,:)=rand(2,6)
Unable to perform assignment because the size of the left side is 1-by-6 and the size of the right side is 2-by-6.

Community Treasure Hunt

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

Start Hunting!