plot values of same index from two vectors

10 views (last 30 days)
I have three vectors with the same amount of elements (pre values and post values of all participants, respectively and control data)
I would like to create a plot of the individual change, so x-axis = pre, post, control, y-axis = value of vector index and then plot the first index of the vector pre together with the first index of the vector post and so on while control data is seperate in the third 'column'. I can't figure out how to do this.
It should look something like this at the end.
  1 Comment
Megumi Fukuda
Megumi Fukuda on 14 Jun 2021
Can you clarify the struture of your data and what you want to do? I assume you have three vectors (v_pre, v_post, and v_cont) without any missing data, and v_pre(1), v_post(1), and v_cont(1) is the pre data of participant1. What do you mean by "while control data is seperate in the third 'column'"? Is it graphical representation of the graph (i.e. no lines between v_post and v_cont)?

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 14 Jun 2021
Edited: Scott MacKenzie on 14 Jun 2021
Here's what I put together. It looks a bit crazy because the data are just random numbers. But, I think it achieves more or less what you are after, given your example plot.
n = 8; % number of participants
x = 4; % number of data points: pre1, pre2, post1, post1
% test data (replace with your data)
data = rand(x,n) * 100;
control = rand(1,n) * 100;
plot(1:x, data, '-o');
hold on;
plot(x+1, control, 'ok', 'markerfacecolor', [.4 .4 .4]);
ax = gca;
ax.XLim = [0 6];
ax.YLim = [0 120];
ax.XLabel.String = 'Condition';
ax.XTickLabel = { '' '1Pre' '2Pre' '1Post' '2Post' 'Control' ''};

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!