Thread Subject: Writing/saving multiple variables with new lines between

Subject: Writing/saving multiple variables with new lines between

From: Markus Due Jakobsen

Date: 20 May, 2008 10:59:02

Message: 1 of 2

Hi,

Is it possible to save or use af write-function which
saves/writes multiple variables (vectors with different
lengths) and includes a new line (space) between each
variable?

Like:

x=[1:5]'
Y=[5:9]'

% Save-output should look like this..
Output=
1
2
3
4
5
     %New line (without numbers/data)
6
7
8
9


Thanks,
Markus

Subject: Writing/saving multiple variables with new lines between

From: Miroslav Balda

Date: 20 May, 2008 12:59:04

Message: 2 of 2

"Markus Due Jakobsen" <markusdue@gmail.com> wrote in message
<g0uatm$aaj$1@fred.mathworks.com>...
> Hi,
>
> Is it possible to save or use af write-function which
> saves/writes multiple variables (vectors with different
> lengths) and includes a new line (space) between each
> variable?
>
> Like:
>
> x=[1:5]'
> Y=[5:9]'
>
> % Save-output should look like this..
> Output=
> 1
> 2
> 3
> 4
> 5
> %New line (without numbers/data)
> 6
> 7
> 8
> 9
>
>
> Thanks,
> Markus
>

Hi

Try the following code:

x=(1:5)';
y=(5:9)';
fid=fopen('test.txt','w');
fprintf(fid,'Output=\n');
fprintf(fid,'%d\n',x);
fprintf(fid,'\n'); % New line
fprintf(fid,'%d\n',y);
close(fid);

Its all. The required output is in the file 'test.txt'.

Mira

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
saving Markus Due Jakobsen 20 May, 2008 07:00:04
multiple Markus Due Jakobsen 20 May, 2008 07:00:04
variables Markus Due Jakobsen 20 May, 2008 07:00:04
rssFeed for this Thread

Public Submission Policy

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 Disclaimer prior to use.

Contact us at files@mathworks.com