Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2

8 次查看(过去 30 天)
Hi, I am unable to understand what the error means and at which line of the code it is directed towards. Can someone help me with this?
Thanks a lot!
This is my code so far :
%% Load dataset and remove data about position of moving platform from array
Data_1 = readtable('RFID_1.csv');
Data_2 = readtable('RFID_2.csv');
Data_3 = readtable('RFID_3.csv');
Data_4 = readtable('RFID_4.csv');
data_1 = table2array(Data_1(:, 1:6));
data_2 = table2array(Data_2(:, 1:6));
data_3 = table2array(Data_3(:, 1:6));
data_4 = table2array(Data_4(:, 1:6));
meansData_1 = zeros(6,1);
figure('Name', 'Phase readings for tag', 'WindowState', 'maximized');
tiledlayout(2,6, 'TileSpacing', 'compact')
%% Start to calculate phase differences
for i=1:6
x = data_1(i,:);
x_multidim=[cosd(x); sind(x)];
x_t=x_multidim';
nexttile;
idx = dbscan(x_t,0.1,5);
gscatter(x_t(:,1),x_t(:,2),idx,'kr','*');
title(append('At ', num2str(table2array(Data_1(i,1))),'cm'));
xlim([-1.2 1.2]);
ylim([-1.2 1.2]);
viscircles([0 0],1, 'Color', 'b', 'LineWidth',0.1);
storeall = double.empty(0,2);
for j=1:6
if(idx(j)==1)
storeall = [storeall;x_t(j,:)];
end
end
storeall_filt=rmoutliers(storeall);
meansData_1(i,:)=mean(storeall);
hold on;
plot(meansData_1(i,1),meansData_1(i,2),'XData','MarkerSize',20,'LineWidth',1.5,'Color','magenta','DisplayName','mean');
end
PhData_1 = atan2d(meansData_1(:,2),meansData_1(:,1));
for k=0:6
if(PhData_1(k)<0)
PhData_1(k)=360+PhData_1(k);
end
end

采纳的回答

Voss
Voss 2022-11-23
The error message will tell you which line the error occurred on, but I think it's this one:
meansData_1(i,:)=mean(storeall);
And the error happens because meansData_1 has one column, but storeall has two columns (so mean(storeall) has two columns).
To fix it, initialize meansData_1 to have two columns before the for loop:
meansData_1 = zeros(6,2); % instead of zeros(6,1)
Then you will get another error a couple of lines later with the plot call because of an extraneous 'XData' argument that should be removed:
plot(meansData_1(i,1),meansData_1(i,2),'MarkerSize',20,'LineWidth',1.5,'Color','magenta','DisplayName','mean')
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by