Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

excel - MATLAB: Scatter Plot with matrix data

I am trying to perform the scatter plot of X and Y matrices, each of size 54x365, with the following code on MATLAB. The data was extracted from excel.

clc
clear
A = xlsread('Test_data.xlsx', 'Sheet 1', 'F3:NF56');
B = xlsread('Test_data.xlsx', 'Sheet 2', 'F3:NF56');
scatter (A,B)

Although they are of similar size, MATLAB produces the following statement:

Error using scatter (line 44)
X and Y must be vectors of the same length.

Error in Untitled2 (line 11)
scatter(A,B)

Note the following:

A = [ A, B, C, D, E ;
      F, G, H, I, J ]

B = [ a, b, c, d, e ;
      f, g, h, i, j ]

The variables (A,a), (B,b) and so on are plotted so as to produce a scatter plot.

I need help to perform the scatter plot. Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Reshaping the arrays as row vectors may allow the scatter() function to plot the data. Here the arrays are reshaped to have dimensions that are 1 by Number_Of_Values in each array.

%Generating random test data%
A = rand(54,365);
B = rand(54,365);

%Reshaping to allow plotting%
Number_Of_Values = numel(A);
A = reshape(A,[1 Number_Of_Values]);
B = reshape(B,[1 Number_Of_Values]);

scatter(A,B);

Ran using MATLAB R2019b


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...