Plotting one value from a vector

18 ビュー (過去 30 日間)
Gabriela
Gabriela 2023 年 9 月 15 日
回答済み: Mathieu NOE 2023 年 9 月 15 日
I have a file where they give me a vector with multiple measurements (the vector is 100x500). I need to plot only one of thoes measurements onto the graph but my code is plotting all of them since i don't know how to plot one. How can I plot only one? Thank you for the help! This is my code:
(figure #2 is where im having the problem)
clear;
clc;
L=load("ver.mat");
t=linspace(0,500,numel(L.actual_ver));
Ensembl_avg=mean(L.ver);
figure(1);
plot(t,Ensembl_avg);
hold on;
plot(t,L.actual_ver);
grid on;
xlabel('Time');
ylabel('Ensemble Average and Actual Signal');
title('Ensemble Average and Actual Signal VS Time:');
figure(2);
plot(t,L.ver);
hold on;
plot(t,L.actual_ver);
  1 件のコメント
Image Analyst
Image Analyst 2023 年 9 月 15 日
That's not a 1-D vector, it's a 2-D matrix. Which value from the matrix do you want to plot? Try something like
plot(L.ver(row, column), 'b.', 'MarkerSize', 50);

サインインしてコメントする。

回答 (1 件)

Mathieu NOE
Mathieu NOE 2023 年 9 月 15 日
hello
simply change this
figure(2);
plot(t,L.ver);
into :
figure(2);
channel = 50; % pick value between 1 and 100
plot(t,L.ver(channel,:));
also I wondered if there is a small but in your time vector t
we know that you have 500 samples but when you write :
t=linspace(0,500,numel(L.actual_ver));
this means you have a time vector that goes from 0 to 500 with 500 samples so time increment is (500-0) / (500 -1 ) = 1.002
I just thought that maybe the time increment was 1 so I opted for this way of creating the time vector
t=(0:numel(L.actual_ver)-1);
forget this if I'm wrong
all the best
full code :
L=load("ver.mat");
t=(0:numel(L.actual_ver)-1);
Ensembl_avg=mean(L.ver,1);
figure(1);
plot(t,Ensembl_avg);
hold on;
plot(t,L.actual_ver);
grid on;
xlabel('Time');
ylabel('Ensemble Average and Actual Signal');
title('Ensemble Average and Actual Signal VS Time:');
figure(2);
channel = 50; % pick value between 1 and 100
plot(t,L.ver(channel,:));
hold on;
plot(t,L.actual_ver);

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by