how to append a matrix with a nested for loop?
5 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
NIVEDITA MAJEE
2022 年 6 月 29 日
Hello,
Please take a look at the following documentation for expanding matrices:
You can also take a look at this MATLAB answer:
Hope this helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!