Re: How to save several variables with the same prefix?



Thanks for answering.
s=[3 5 7 9]
X is a matrix of size 200X150
for i=1:length(s)
window=s(i)
Xbarra=Average filter of X of size s(i)
X=X-Xbarra % residue
I want to save X at this point with a name ResWind_s(i) %for example if i=1 will be ResWind_3
end
There is not logic error X is not the matrix zero, what I mean with Xbarra is a matrix of the same size as X but each value is replaced by the mean of the window of size s(i)

well the problem is that if I write fprintf(' filename' , X) in each iteration it will create only one file named filename, it will overwrite it each time and I end up with only one file that has the value of X but just for s(i)=11.
The idea behind filename=sprintf('ResWind_%d.txt',s(i)); is create the string this is why I put it inicialy without ' '.
So I think my problem is how to create a variable that hold a string

Thanks for answer me why fwrite did not work, that was somenthing I did not know but after fprintf did not work I begun to explore other ideas, I need it with format so fwrite is not an option.

So I create the variable filename with the idea that when I put it inside of fprintf it will take the string
dpb <none@xxxxxxx> wrote in message <h623fe$fen$1@xxxxxxxxxxxxxxxxxxxxxxxxxx>...
Maider Marin wrote:
I am trying to save to a txt format a matrix that change with a for
loop, I want to save the matrix for each iteration and save it with a
name that references the size of the window ( filter) I am using in my
process, for example four files: ResWind_3, ResWind_5, ResWind_7, ResWind_9
this is more or less I am doing
s=[3 5 7 9]
X is a matrix of size 200X150
for i=1:size(s,2)

length(s) is a little more succinct...

window=s(i)
Xbarra=X after passing thru average filter of size s(i)
X=X-Xbarra % residue

The above will leave X == 0 as it reduces to Xbarra-Xbarra after the
assignment preceding this line.
end

I want to save the matrix X in each iteration. I want four files:
ResWind_3, ResWind_5, ResWind_7, ResWind_9
I try
filename=sprintf('ResWind_%d.txt',s(i));
fid=fopen(filename,'wt');
fwrite(fid, X); %( fprintf(filename, X) did not work)

fprintf() didn't work as written because you didn't supply a format
string. I'd think that would've barfed...

fwrite() is unformatted (ML calls it "binary") write but the above
fopen() statement says it's to be opened as text file. You need to be
consistent--use the 't' w/ fprintf(); not w/ fwrite()

fclose(fid)
and also
save filename X
but the best I got was open a file with the name I want but the variable never was written. In the case of save it create one file name filename just with the result of the window fo size 9.
so my question is there is any way to do that?

Basic idea is correct you simply have a couple logic errors in your
code. Pick whether you want the data in a human-readable format or just
for saving for later use. If the former use fprintf() and fix the
format string problem; if the latter use fwrite() and fix the file
access type in fopen().

As for whether the logic error in the computation is actual or just a
typo or other artifact of creating the post I can't tell for certain but
it isn't right as posted so check that your result is ok.

And, of course, the file-related stuff has to go back into the for loop
or it'll only be active after the loop has completed.

--
.



Relevant Pages

  • Re: Handling floating point with decimal comma separator to filter a form
    ... Lets say the user wants to filter values between 1,1 and 1,9 (note that the user wiil enter the number with a comma sparator, not with a dot - and the Standard format will be of no help here). ... Dim strWhere As String ...
    (microsoft.public.access.formscoding)
  • Re: Filtering a query for a form based on dates
    ... The best format to use is either the North American format ... Public Function SQLDateAs String ... Now, when you wish to apply a filter to your form, I recommend that you do ... the whole form when the textboxes are updated. ...
    (microsoft.public.access.formscoding)
  • Re: unit testing C++ code from perl
    ... void ReportAssert(char const* description, char const* filename, int const ... That's probably the complaint string for an error. ... Then we have a filename and lineNumber. ... void FormatToStream(MemoryOutStream& stream, char const* format, ValueType const& value) ...
    (comp.programming)
  • Re: Handling floating point with decimal comma separator to filter a form
    ... Standard format will be of no help here). ... a desire to filter this field so it lies between the 2 numbers ... Dim strWhere As String ...
    (microsoft.public.access.formscoding)
  • Re: Timestamp to a string
    ... > concatenate a date string" which I think we can see it isn't. ... > of a date which doesn't mistake some legitimate filename for your ... I want to give an option of specifying the timestamp format to ...
    (comp.lang.java.programmer)

Loading