how to save/write images using for loop in one .mat file

I want to save file path and roi of 10 images coming from a loop in one .mat file

4 件のコメント

Rik
Rik 2020 年 6 月 2 日
The most efficient way is probably to store your output data is a variable and store it after the loop, instead of appending the data inside the loop.
richa golash
richa golash 2020 年 6 月 2 日
I tried, but it is overwriting the previous value. I want to save them in new row
Ameer Hamza
Ameer Hamza 2020 年 6 月 2 日
Can you show the code?
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 6 月 2 日
Save the images in cell array (multiple_rows,one cloumn), later cell2mat and save?

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2020 年 6 月 2 日

0 投票

As Ameer suggests: you should share the code, so we can suggest how you can implement indexing.
The point is that your code currently looks like the top block, and should look like the bottom block.
for n=1:10
out=n+rand;%will overwrite
end
out=zeros(1,10);
for n=1:10
out(n)=n+rand;
end

6 件のコメント

richa golash
richa golash 2020 年 6 月 2 日
C = cell(4,2);
for k = 1:4
%T = load(fullfile(D,'X_*.mat'));
F=sprintf('Img21/X_%d.mat',k);
%outputBaseFileName = sprintf('%d.png', index);
% outputFullFileName2 = fullfile(Name, outputBaseFileName);
T=load(F);
C(k,2) = struct2cell(T);
end
M = vertcat(C{:});
save('Z.mat','M')
In this example i have taken 4 mat file each mat file have 2 variables. i want to club them in one mat file
Rik
Rik 2020 年 6 月 2 日
Do all the mat files have different variable names? Or do you want to create a struct array? What data shape do you want to end up with?
richa golash
richa golash 2020 年 6 月 2 日
They have same variable. A table form with nx2
Rik
Rik 2020 年 6 月 2 日
Can you write the code with numbered variables so I can suggest the exact code you could use?
%e.g. this:
k=1;F=sprintf('Img21/X_%d.mat',k);
C_1_1=T.A;C_1_2=T.B;
k=2;F=sprintf('Img21/X_%d.mat',k);
C_2_1=T.A;C_2_2=T.B;
M={C_1_1,C_1_2;C_2_1,C_2_2};
(you shouldn't be using code like this, but it helps to show what the output should be)
richa golash
richa golash 2020 年 6 月 2 日
Thanks i will try
richa golash
richa golash 2020 年 6 月 4 日
I resolved this problem by using struct2table function. Thanks for suggesting encouraging solution

サインインしてコメントする。

タグ

質問済み:

2020 年 6 月 2 日

コメント済み:

2020 年 6 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by