问题描述
我正在尝试在 MATLAB 上使用以下代码执行 X
和 Y
矩阵的散点图,每个矩阵的大小为 54x365
。数据提取自excel。
clc
clear
A = xlsread('Test_data.xlsx','Sheet 1','F3:NF56');
B = xlsread('Test_data.xlsx','Sheet 2','F3:NF56');
scatter (A,B)
尽管它们的大小相似,但 MATLAB 会生成以下语句:
Error using scatter (line 44)
X and Y must be vectors of the same length.
Error in Untitled2 (line 11)
scatter(A,B)
注意以下几点:
A = [ A,B,C,D,E ;
F,G,H,I,J ]
B = [ a,b,c,d,e ;
f,g,h,i,j ]
绘制变量 (A,a)
、(B,b)
等以生成散点图。
我需要帮助来绘制散点图。谢谢。
解决方法
将数组重新整形为行向量可能允许 scatter()
函数绘制数据。这里的数组被重新整形为每个数组中的维度为 1 x Number_Of_Values
。
%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);
使用 MATLAB R2019b 运行