【问题标题】:MATLAB: Scatter Plot with matrix dataMATLAB:带有矩阵数据的散点图
【发布时间】:2021-01-06 19:35:28
【问题描述】:

我正在尝试在 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)等绘制成散点图。

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

【问题讨论】:

  • 在右侧的 MATLAB 工作区面板中显示的矩阵/向量 AB 目前的大小/维度是多少?
  • 两者都是 54x365 双倍。

标签: excel matlab matrix plot scatter


【解决方案1】:

将数组重塑为行向量可能允许scatter() 函数绘制数据。在这里,数组被重新调整为每个数组中的维度为 1 by 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 运行

【讨论】:

  • 没问题,乐于助人。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-09
  • 1970-01-01
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多