writing a cat file

i have a values
A=[m V SD],where m is mean, v is variance ,sd is standard dev of an image
now i want to write A into folder ,my folder name is new1
i have 100 images ,and have found m,v,sd for all images
so in that folder i need to store all values i.e(A1 to A100) please help

4 Comments

Jan
Jan on 15 Dec 2011
Do you want to write the values to one file or to 100 files? What have you tried so far and which problems occurred? I suggest reading the documentation. Writing numerical vectors to files is explained there repeatedly and exhaustively.
Hello, Pat
Writing into MAT files or Text files??
Pat
Pat on 15 Dec 2011
text file
Jan
Jan on 15 Dec 2011
This is your 107th question in this forum. It is time to learn how to include all necessary details to a question. Currently you could get an acceptence rate of only 19%. Improving the quality of your questions would be a very good idea.
E.g. at first you are talking of the vector A and explain, what the values mean. But for the actual problem rand(1,4) would be equivalent also. In opposite to such unnecessary information, it is not explained anywhere whar "A1" and "A100" is. Later on in this thread it comes out, that you can to save a struct instead.
Finally, when I see the bunch of problems you have posted here, it is very hard for me to imagine, that you cannot find out, how to write some numbers to a file. Pat, this is extremly basic.

Sign in to comment.

 Accepted Answer

Hello, Pat
I just give you small example.
Then, I hope you can use it or do modification on it for your purpose.
clear; clc;
for cnt = 1 : 10
m = 255*rand;
V = 255*rand;
SD = 255*rand;
filename = strcat(pwd,'\New1\A',num2str(cnt),'.txt');
fid = fopen(filename, 'w');
fprintf(fid,'mean : %.2f\n variance : %.2f\n standard dev : %.2f\n',m,V,SD);
fclose(fid);
end

6 Comments

Pat
Pat on 15 Dec 2011
F =
Contrast: 0.2963
Correlation: 0.9414
Energy: 0.1124
Homogeneity: 0.8891
for these i do as per ur code i get error ,please help
Error using ==> fprintf
Function is not defined for 'struct' inputs.
Error in ==> Untitled at 27
fprintf(fid,'values : %.2f\n ',F);
Pat
Pat on 15 Dec 2011
I want to write F
Of course you cannot write a struct with command fprintf with format %.2f
It might be :
for cnt = 1 : 3
F = struct;
F.Contrast = 0.2963;
F.Correlation = 0.9414;
F.Energy = 0.1124;
F.Homogeneity = 0.8891;
filename = strcat(pwd,'\New1\AA',num2str(cnt),'.txt');
fid = fopen(filename, 'w');
fprintf(fid,'Contrast : %.2f\n Correlation : %.2f\n Energy : %.2f\n Homogeneity : %.2f\n',F.Contrast,F.Correlation,F.Energy,F.Homogeneity);
fclose(fid);
end
Jan
Jan on 15 Dec 2011
@Chandra: FULLFILE is more secure than "strcat(pwd,'\New1\A',num2str(cnt),'.txt')". e.g. if the current folder is "C:\" the trailing file separator is considered.
@Pat: You've asked a question and Chandra gave a working asnwer. Afterwards you modify the conditions. It is obvious that this wastes the time of Chandra and all others who want to assist here.
Pat
Pat on 15 Dec 2011
no jan,i had two different questions,i got the answers,thank u chandra

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation 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!