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 commentaires

Cris LaPierre
Cris LaPierre le 1 Juin 2023
Modifié(e) : Cris LaPierre le 1 Juin 2023
What count do you want the histogram to be showing? Let's pick the simple case of P1 with 5 times. What should the plot for that participant look like? If I divide all 5 times by the total time, I am left with 5 normalized percentages. Which of these is the value you want to display?
Emma Walker
Emma Walker le 1 Juin 2023
Emma Walker
Emma Walker le 1 Juin 2023
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.

Connectez-vous pour commenter.

 Réponse acceptée

the cyclist
the cyclist le 1 Juin 2023
Modifié(e) : the cyclist le 1 Juin 2023
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 commentaires

Emma Walker
Emma Walker le 1 Juin 2023
This is it, yes! How can I embed this in a loop and do it for all the participants? This is what I am working with.
% Initialize vectors
Timestamps = zeros(24,67); %Hz
TotalTimeVectors = zeros(24,5*1437);
fn = fieldnames(dataStruct); %datastruct contains the timestamps
fn = fn(2:end);
%loop through the participants
figure()
hold on
for i=1: numel(fn)
% Timestamps in seconds to Hz to accomodate oxy-Hb data
% a Timestamp is when a participant speaks an idea
Timestamps(i,:) = 5*dataStruct.(fn{i}); %Hz
TotalTimeVectors(i,1:length( Participants.(fn{i}).data(:,2:2:end) ) ) = 1:1:length( Participants.(fn{i}).data(:,2:2:end) ); %pull HbO, skip Hbr
%insert plotter here
end
Emma Walker
Emma Walker le 1 Juin 2023
How could I use the set function you used for 24 participants?
Emma Walker
Emma Walker le 1 Juin 2023
Here is what I am thinking right now but the figure came out like so:
Timestamps = zeros(24,67); %Hz
%TotalTimeVectors = zeros(24,5*1437);
fn = fieldnames(dataStruct); %datastruct contains the timestamps
fn = fn(2:end);
%loop through the participants
figure()
hold on
for i=1: numel(fn)
% Timestamps in seconds to Hz to accodate oxy-Hb data
% a Timestamp is when a participant speaks an idea
Timestamps = 5*dataStruct.(fn{i}); %Hz
%TotalTimeVectors(i,1:length( Participants.(fn{i}).data(:,2:2:end) ) ) = 1:1:length( Participants.(fn{i}).data(:,2:2:end) ); %pull HbO, skip Hbr
Timestamps = Timestamps(~isnan(Timestamps));
%insert plotter here:
plot(Timestamps/max(Timestamps),1,".","MarkerSize",32,"Color","black");
end
set(gca,"YLim",[0.5 24.5],"YTick",1:1:24)
I'm guessing a bit here, because I did not really grok your entire code, but I think it should just be
% plotter
TTV = TotalTimeVectors(i,1:length( Participants.(fn{i}).data(:,2:2:end) ) ); % For convenience
plot(TTV/max(TTV),i,".","MarkerSize",32,"Color","black");
and then
set(gca,"YLim",[0.5 numel(fn)+0.5],"YTick",1:numel(fn))
after the loop.
If that's not quite right, maybe you can figure it out. Otherwise, you probably need to post the data for me to fix it.
Emma Walker
Emma Walker le 1 Juin 2023
Modifié(e) : Emma Walker le 1 Juin 2023
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 le 1 Juin 2023
Nevermind.. I just realized my blunder. Thank you for your help!

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 1 Juin 2023

0 votes

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.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Version

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by