Clear Filters
Clear Filters

Plotting one value from a vector

35 views (last 30 days)
Gabriela
Gabriela on 15 Sep 2023
Answered: Mathieu NOE on 15 Sep 2023
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 Comment
Image Analyst
Image Analyst on 15 Sep 2023
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);

Sign in to comment.

Answers (1)

Mathieu NOE
Mathieu NOE on 15 Sep 2023
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);

Community Treasure Hunt

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

Start Hunting!