Scatter X and Y must be of same length
39 views (last 30 days)
Show older comments
I have a 100x3 array named data that I wanted a scatter plot of
I did Scatter(data,zeros(length(data),3),'bs','filled')
Here X and Y are of same length,but the error states otherwise.
Help please?
0 Comments
Accepted Answer
Star Strider
on 5 Apr 2014
Does this do what you want?
data = rand(100,3);
figure(1)
scatter3(data(:,1), data(:,2), data(:,3), 'bs', 'filled')
Replace my data statement with yours so you don’t overwrite it. I created it to test the code.
2 Comments
More Answers (3)
Image Analyst
on 5 Apr 2014
X is data - a 100 by 3 array. And you're scattering it against an array of all zeros. Why? If it even does scatter 2D array (which I doubt), all your y values will be zero. And the documentation says that X must be a vector, in other words, a 1D array, not a 2D 100 row by 3 column matrix. Maybe you want
scatter(data(:,1), data(:,2));
I have no idea. By the way, MATLAB is case sensitive so you should use scatter() not Scatter().
0 Comments
the cyclist
on 5 Apr 2014
For the scatter command, the inputs have to be vectors, not arrays.
scatter(data(:,1),data(:,2))
would plot the first column against the second column.
0 Comments
Lusiana Efrizoni
on 7 Sep 2020
can you help me, why this graphic like this?
I used Matlab program below
data=xlsread('MHSR.xlsx');
x1=data(:,2);
x2=data(:,3);
x3=data(:,4);
x4=data(:,5)
y = data(:,6);
X = data(:,1:4);
b = regress(y,X);
%persamaan=X\y;
[br k]=size(X);
for i=1:br
predik(i)=0.1109+(0.1203*X(i,2))-(0.8380*X(i,3))-(1*X(i,4));
end
predik=predik';
jum_mse=0;
for i=1:br
jum_mse=jum_mse+((y(i)-predik(i))^2);
end
rata_mse=jum_mse/br;
model = fitlm(X,y)
y2 = predict(model,X);
hold on
figure(1)
scatter(data(:,2), data(:,2), data(:,4),data(:,5),'filled')
%scatter(X,y2,21,'filled')
line(X,y2)
%plot(y);
%plot(y2);
xlabel('Data Ke-'),ylabel('INDEKS PRESTASI KUMULATIF')
title('Data IPK');
grid on
legend('target','line fitting')
hold off
1 Comment
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!