Plotting different sized vectors

조회 수: 6 (최근 30일)
Emma Walker
Emma Walker 2023년 6월 1일
댓글: Emma Walker 2023년 6월 1일
I am trying to visualize different participant data from an experiment. Participants took different amounts of time to complete the task and so the length of their time vectors is different. In the experiment, participants indicated feedback to us which we took down a timestamp of. Some participants produced 4 timestamps, some produced as much as 60. At the risk of redundancy, I am going to try to explain this thoroughly: I want to visualize this as a horizontal histogram basically where the horizontal axis is the normalized percentage of their total time and where their feedback occured with repect to their total amount of time they took to complete the task. The vertical axis is the participant number. How can I do this when some produced more data points than others?
Example:
P1: 4, 24, 130, 470, 500
P2, 3, 8, 22, 37, 59, 83, 111, 148, 209
Where the numbers are the timestamps i.e. at 4 seconds, P1 indicated feedback.
Ideally, I would like to make two figures, the first where the horizontal is a time axis that has not been normalized and showcases how some participants took longer than others and the second, described above, where the time axis has been normalized and all points are all plotted against the percentage of the whole time.
  댓글 수: 3
Emma Walker
Emma Walker 2023년 6월 1일
Emma Walker
Emma Walker 2023년 6월 1일
Maybe it should not be a histogram actually. Forget I said that. That is just how I was thinking about it originally. I want all the participants on the same figure.

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2023년 6월 1일
편집: the cyclist 2023년 6월 1일
Here is one way. If you have many participants, I would generalize this a bit differently (e.g. by storing participant vectors in a cell array, using a loop). But I don't want to go too far down this path before confirming this is generally what you are looking for.
P1 = [4, 24, 130, 470, 500];
P2 = [3, 8, 22, 37, 59, 83, 111, 148, 209];
figure
hold on
plot(P1/max(P1),1,".","MarkerSize",32,"Color","black");
plot(P2/max(P2),2,".","MarkerSize",32,"Color","black");
set(gca,"YLim",[0.5 2.5],"YTick",[1 2])
  댓글 수: 6
Emma Walker
Emma Walker 2023년 6월 1일
편집: Emma Walker 2023년 6월 1일
I think you were looking at the wrong line. I have removed it for clarity.
I have run the following and have the same result
% Initialize vector
Timestamps = zeros(24,67); %Hz
fn = fieldnames(dataStruct); %datastruct contains the timestamps
fn = fn(2:end);
figure()
hold on
for i=1: numel(fn) %loop through the participants
Timestamps = 5*dataStruct.(fn{i}); %Hz
Timestamps = Timestamps(~isnan(Timestamps));
%insert plotter here:
plot(Timestamps/max(Timestamps),1,".","MarkerSize",32,"Color","black");
end
set(gca,"YLim",[0.5 numel(fn)+0.5],"YTick",1:numel(fn))
So I need to include the y-axis variation in the loop somehow - how do you do that?
Emma Walker
Emma Walker 2023년 6월 1일
Nevermind.. I just realized my blunder. Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2023년 6월 1일
If you have an idea in your mind of roughly what you want the plot to look like, open the Plots tab of the Toolstrip and click the downward facing triangle on the right side of the Plots section of that tab. Find a thumbnail that looks close to what you're envisioning then search for the documentation for the function whose name is below the thumbnail to learn more about how to use it.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by