creating subplots for different array values
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Paquerette
el 27 de En. de 2024
Comentada: Voss
el 31 de En. de 2024
Asking for patience as I am very new to coding and only started Matlab in October. Not sure if my code if correct but it is running and looks like it's doing what I hope.
I have data that has been run through a DNN so I have 25 layers for each participant, each in a separate file which makes 100 files for 4 participants for example.
I would like to pull out the data from only 3 specific layers for only 4 specific participants and plot that data on 3 separate subplots by layer. I currently have VERY long code that I believe does the job, but I feel like nested for loops may be possible. Among other things, I can't figure out how to do that with the different subplots. For the moment, as you can see, I have manually filled in the layer (ll) and subplot position.
layerSel = [1 13 25]; % Selected layers
indLaySel = layerSel([1:end])
ssSel = [102 104 112 121]; % Selected participants
selSS = ssSel([1:end])
nBlocks = 10;
nTrialsPerBlock = 51;
stimLang = strcmp(batch_types,'valid')'; % creates column vector with value of 1 when 'valid' in batchtypes
stimLang = stimLang(1:nBlocks*nTrialsPerBlock).';
for ll = 1
for ss = selSS
load(['proj24/english_layer' num2str(layerSel(ll)) '_ss' num2str(ss) '_tr.mat'])
%creates stimulus matrix
stimulus = stimulus_durations(1:10,:); % takes rows 1-10, all columns
stimLengthV = stimulus.'; % pivots data vertically
stimLength = stimLengthV(:); % takes all columns and puts in 1 column, codes as x variable
stimLengthR = round(stimLength);
%creates distance matrix
avDist = avDists(:,:,3); % takes third dimension from avDist
avDist = avDist(:,:,1); % takes all rows, all columns, sheet 1
distance = avDist(:); % takes all columns from sheet 1 and puts in 1 column
% create table for ease of viewing ;)
dataTable = table(stimLength,distance,stimLang);
%create plot
subplot(1,3,1);
gscatter(stimLengthR,distance,stimLang,"kb","ox")
title('Layer 1')
xlabel('stimulus length')
ylabel('distance')
legend('pseudo','valid')
end
end
for ll = 13
for ss = selSS
load(['/proj24/english_layer' num2str(layerSel(ll)) '_ss' num2str(ss) '_tr.mat'])
%creates stimulus matrix
stimulus = stimulus_durations(1:10,:); % takes rows 1-10, all columns
stimLengthV = stimulus.'; % pivots data vertically
stimLength = stimLengthV(:); % takes all columns and puts in 1 column, codes as x variable
stimLengthR = round(stimLength);
%creates distance matrix
avDist = avDists(:,:,3); % takes third dimension from avDist
avDist = avDist(:,:,1); % takes all rows, all columns, sheet 1
distance = avDist(:); % takes all columns from sheet 1 and puts in 1 column
% create table for ease of viewing ;)
dataTable = table(stimLength,distance,stimLang);
%create plot
subplot(1,3,2);
gscatter(stimLengthR,distance,stimLang,"kb","ox")
title('Layer 13')
xlabel('stimulus length')
ylabel('distance')
legend('pseudo','valid')
end
end
for ll = 25
for ss = selSS
load(['/proj24/english_layer' num2str(layerSel(ll)) '_ss' num2str(ss) '_tr.mat'])
%creates stimulus matrix
stimulus = stimulus_durations(1:10,:); % takes rows 1-10, all columns
stimLengthV = stimulus.'; % pivots data vertically
stimLength = stimLengthV(:); % takes all columns and puts in 1 column, codes as x variable
stimLengthR = round(stimLength);
%creates distance matrix
avDist = avDists(:,:,3); % takes third dimension from avDist
avDist = avDist(:,:,1); % takes all rows, all columns, sheet 1
distance = avDist(:); % takes all columns from sheet 1 and puts in 1 column
% create table for ease of viewing ;)
dataTable = table(stimLength,distance,stimLang);
%create plot
subplot(1,3,3);
gscatter(stimLengthR,distance,stimLang,"kb","ox")
title('Layer 25')
xlabel('stimulus length')
ylabel('distance')
legend('pseudo','valid')
end
end
0 comentarios
Respuesta aceptada
Voss
el 28 de En. de 2024
layerSel = [1 13 25]; % Selected layers
ssSel = [102 104 112 121]; % Selected participants
nBlocks = 10;
nTrialsPerBlock = 51;
stimLang = strcmp(batch_types,'valid')'; % creates column vector with value of 1 when 'valid' in batchtypes
stimLang = stimLang(1:nBlocks*nTrialsPerBlock).';
Nlayers = numel(layerSel);
Nparticipants = numel(ssSel);
figure();
for ll = 1:Nlayers
for ss = 1:Nparticipants
S = load(fullfile('proj24',sprintf('english_layer%d_ss%d_tr.mat',layerSel(ll),ssSel(ss))));
%creates stimulus matrix
stimLengthR = round(reshape(S.stimulus_durations(1:10,:).',[],1));
%creates distance matrix
distance = reshape(S.avDists(:,:,3),[],1);
%create plot
subplot(1,Nlayers,ll);
gscatter(stimLengthR,distance,stimLang,"kb","ox")
hold on
end
title(sprintf('Layer %d',layerSel(ll)));
xlabel('stimulus length')
ylabel('distance')
legend('pseudo','valid')
end
6 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!