Save each output in one file

Nur Farahin · Jan 9, 2023 · 2K views
Question
Hi, anybody can help me from this code,   I want to save all peaksnr output into one .csv using writematrix, but this code only save one value into the .csv.   Is there any method i can use to make sure all the output save into one csv.   %% Here is my code indir = uigerdir(cd, 'Select input folder'); directory = dir([indir, '\', '*.jpg']); for i = 1 : length(directory) filename = directory(i).name; ref = imread([indir, '\', filename]); A = imnoise(ref, 'salt & pepper', 0.02); [peaksnr, snr] = psnr(A, ref); fprintf('\n Peak-SNR Original : %0.4f',peaksnr); fprintf('\n SNR Original : %0.4f \n',snr); writematrix(peaksnr, sprintf('psnrO.csv',i+1)) end Thank you for your help.
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 18, 2026

But, i've tried another solution an work for me as well.

 

indir = uigetdir(cd, 'Select input folder');
directory = dir([indir, '\', '*.jpg']);
for i = 1 : length(directory)
    filename = directory(i).name;
    ref = imread([indir, '\', filename]); 
    A = imnoise(ref, 'salt & pepper', 0.02);
    [peaksnr, snr] = psnr(A, ref);
    fprintf('\n Peak-SNR Original : %0.4f',peaksnr);
    fprintf('\n SNR Original : %0.4f \n',snr);
    writematrix(peaksnr,'psnrO.csv','WriteMode','append');
    writematrix(snr,'snrO.csv','WriteMode','append');
    
end

just add the writemode and append argument, then the values will save all in one csv.

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!