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!