Effacer les filtres
Effacer les filtres

how to append a matrix with a nested for loop?

3 vues (au cours des 30 derniers jours)
nines
nines le 29 Juin 2022
Hello,
I have a nested for loop where I want to append the matrix for every for loop.
subjs = {'subj1' 'subj2'}
experiments = {'groundtruth' 'change1' 'change2'}
percent_change_matrix = [] %preallocating
percent_change_control_matrix = []
for s = 1:length(subjs)
subj = subjs{s}
for i = 1:length(experiments)
experiment = experiments{i}
data = load(fullfile('text.txt']))
data = data(:,5)
data(:,i)=data
task(:,i) = data(5,5)
baseline(:,i) = data(5,5)
percent_change(:,i) = ((task-baseline)/baseline)*100
end
percent_change_matrix = [percent_change_matrix; percent_change]
end
where I want my output matrix to look as follows:
groundtruth change1 change2
subj 1 0 10 12
subj2 0 10 12
when right now my output looks like this:
0
0
10
12
0
12
Do you have any suggestions?
Thanks

Réponse acceptée

NIVEDITA MAJEE
NIVEDITA MAJEE le 29 Juin 2022

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by