Thread Subject: What's wrong in my tiny little code?

Subject: What's wrong in my tiny little code?

From: Kuo-Hsien

Date: 21 Sep, 2008 12:38:03

Message: 1 of 2

Hi -

I was wondering anything wrong in this code. It should save many files to another folder, however it just saved them in one file in which the file name is (filename(n).name). Please give me a hand.

Michael

function pad_wx_data
filename = dir ('*.txt');
n=1;
[i,j]=size(filename);
while n<i+1
x = load(filename(n).name);
[rr,cc] = size(x);
day_number = datenum(x(:,1:3));
full_day_number = [min(day_number):max(day_number)]';
y = [full_day_number NaN*ones(length(full_day_number),cc-3)];
[jnk,uix,uiy] = intersect(day_number,full_day_number);
y(uiy,2:size(y,2)) = x(uix,4:cc);
save('/Users/cks/Documents/jon/hfdata/us/WI/test/perl/test_4/out/product/(filename(n).name)', 'y')
n=n+1;
end
clear temp n i j

Subject: What's wrong in my tiny little code?

From: Tom

Date: 21 Sep, 2008 15:15:04

Message: 2 of 2

"Kuo-Hsien " <mchangks@hotmail.com> wrote in message <gb5f7b$3gg$1@fred.mathworks.com>...
> I was wondering anything wrong in this code. It should save many files to another folder, however it just saved them in one file in which the file name is (filename(n).name). Please give me a hand.
>
> save('/Users/cks/Documents/jon/hfdata/us/WI/test/perl/test_4/out/product/(filename(n).name)', 'y')

The line of code above is the problem. The save file name is "(filename(n).name)". Try the following change:

save(['/Users/cks/Documents/jon/hfdata/us/WI/test/perl/test_4/out/product/' filename(n).name], 'y')

This should concatenate filename(n).name onto the end of the path.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com