Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

No tags are associated with this thread.

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.

Contact us