writematrix can't save all the numbers in a variable
6 views (last 30 days)
Show older comments
Hello, I tried to use writematrix to save my results in a variable but not fully succeeded.
I process a raw data at different positions, (1,2,3. etc) each time, and will get a result in corresponding column in the workspace for each postion. pealse see below:
I used the code below to save values but I can only save the latest one and overwrite the privious one. e.g., when I run postion 6, the 754.23 will overwrite the 1025.9 in the excel. then when I run positon 7, the 1006.2 will overwrite 754.23 in the excel. the values were only writen at D2 in the excel, not in the range I designed (D2:M2)
How to get all the values? i.e., from D2 to M2 in the excel, I get 0, 0, 0, 0, 1025.9, 754.23, 1006.2 ......
I read the writematrix tutorial, the M = magic(5) example works, but the method doesn't work for mine.
Thank you!
slice = 7; %position, everytime I change the number, I will get a new result in the same variable, at the corresponding column, e.g., column 7 in this case.
figure; imshow(Maps.kidney.t1(:,:,slice),[0 3000]); colormap('jet');
s = drawrectangle('coordination',[49.44415243 81.4586071 3 3]), wait(s);
mask = createMask(s);
kidney_right_mask(:,:,slice) = mask;
map = Maps.kidney.t1(:,:,slice);
val_mean = mean(map(mask==1))
kidney_right_t1_Mean_ROI1(slice) = val_mean
filename = 'C:\Users\Public\MRI\SZ_SD_1st\M1\Test_ROIs_Values.xlsx';
writematrix(kidney_right_t1_Mean_ROI1(slice),filename,'Sheet',2,'Range','D2:M2')% I only get results at D2, not from D2:M2.
3 Comments
Accepted Answer
Voss
on 13 Dec 2022
Edited: Voss
on 13 Dec 2022
kidney_right_t1_Mean_ROI1(slice) is a scalar (i.e., a single number, a single element of kidney_right_t1_Mean_ROI1). That is what you are writing to the xlsx file.
I think you mean to write the entire kidney_right_t1_Mean_ROI1 instead:
writematrix(kidney_right_t1_Mean_ROI1,filename,'Sheet',2,'Range','D2:M2')
More Answers (0)
See Also
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!