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.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!