creating subplots for different array values

조회 수: 9 (최근 30일)
Paquerette
Paquerette 2024년 1월 27일
댓글: Voss 2024년 1월 31일
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

채택된 답변

Voss
Voss 2024년 1월 28일
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
Paquerette
Paquerette 2024년 1월 31일
I also just reworked so I could use the scatter() function instead of gscatter() - very late to the game in coding but finding it quite fun
Voss
Voss 2024년 1월 31일
It's never too late for a new addiction!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by