首页 > 解决方案 > MATLAB:带有矩阵数据的散点图

问题描述

我正在尝试使用 MATLAB 上的以下代码执行每个大小XY矩阵的散点图。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)以产生散点图。

我需要帮助来执行散点图。谢谢你。

标签: excelmatlabmatrixplotscatter

解决方案


将数组重塑为行向量可能允许scatter()函数绘制数据。Number_Of_Values在这里,数组被重新整形以在每个数组中具有 1 的维度。

%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 运行


推荐阅读