"Ana Beatriz " <email@example.com> wrote in message <firstname.lastname@example.org>... > "Ana Beatriz " <email@example.com> wrote in message <firstname.lastname@example.org>... > > Dear all, > > > > First of all, I should apologise for my first post. I rewrote my code and now the problem I had before was solved. > > Now I have another problem: I cannot save my sequential files. The error message is "Error using save. Filename is too long". I want to save the files per year (such as bath2006_proc.xyz; bath2007_proc.xyz;...). > > I suppose that, as soon as it is inside the loop, it should work, right? > > Please, could someone give me any clue about it? > > > > Best wishes, > > Ana > > > > for y=2006:2014 > > bath = sprintf('bath%d.xyz', y); > > if exist (bath, 'file'); > > data = load(bath); > > else > > fprintf ('File %s does not exist.\n', bath); > > end > > x=data(:,1); %Easting coordinates > > y=data(:,2); %Northing coordinates > > z=data(:,3); %Depth > > %Inverting signals (negative depths are above the water and vice-versa > > z_cd=z*-1; %Depth in Chart Datum > > %Converting to Ordnance Datum (-1.98m) > > z_od=z_cd-1.98; %Depth in OD > > %Saving > > file=sprintf('bath%s_proc.xyz',y); > > save(file); > > end > > > Sorry, > I forgot to say that I want the bath2006_proc.xyz as a matrix format [x y z z_cd z_od]. I have already tried some ways to do that, but I don't know how to make it work... > > Thank you.
If you haven't figured it out already, Ana, note that you are defining y twice--the first time at the beginning of your loop (for y = 2006:2014) and the second time when you reassign the second column to y = data(:,2) So the line file=sprintf('bath%s_proc.xyz',y); is trying to assign the entire column of y to the file name.