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:
How to output to a file??

Subject: How to output to a file??

From: Diego Zegarra

Date: 31 Jan, 2009 23:38:01

Message: 1 of 5

I need to know how to output to a file a couple matrixes. Lets say I have two cell arrays that at the end contain the following values.

ProcessingSequence =cell(3,1)
ProcessingTimes =cell(3,1)

ProcessingSequence{1} = [3, 6, 8, 10]
ProcessingSequence{2} = [5, 1, 9, 7]
ProcessingSequence{3} = [11, 4, 2, 12]

ProcessingTimes{1} = [100, 105, 108, 103]
ProcessingTimes{2} = [115, 101, 109, 107]
ProcessingTimes{3} = [110, 104, 102, 120]

And I want t output this to a .txt file that I create from the code, having the output to look like,

The processing sequence is:
3 6 8 10
5 1 9 7
11 4 2 12

The processing times are:
100 105 108 103
115 101 109 107
110 104 102 120

Thanks for any help!

Subject: How to output to a file??

From: Diego Zegarra

Date: 1 Feb, 2009 01:24:02

Message: 2 of 5

Can anyone please help or send me in the right direction? Thanks

Subject: How to output to a file??

From: Walter Roberson

Date: 1 Feb, 2009 08:05:06

Message: 3 of 5

Diego Zegarra wrote:

> ProcessingSequence{1} = [3, 6, 8, 10]
> ProcessingSequence{2} = [5, 1, 9, 7]
> ProcessingSequence{3} = [11, 4, 2, 12]

> And I want t output this to a .txt file that I create from the code, having the output to look like,
>
> The processing sequence is:
> 3 6 8 10
> 5 1 9 7
> 11 4 2 12

Is there any particular rule we can use to compute the irregular spacing you want,
or should we just take the irregular spacing to be illogical but "Just do it!"?

It would be much easier if you had chosen a different spacing, such as
"align the last digit for each column" or "align the first digit for each
column"... then for the numeric parts you could have used (e.g.)

sprintf('%4d %4d %4d %4d\n', cell2mat(ProcessingSequence) .');

but as it is now in your question, the irregular spacing would require a different
format for each line.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: How to output to a file??

From: Diego Zegarra

Date: 1 Feb, 2009 17:02:02

Message: 4 of 5

The spacing can be anything, it sounds good to actually align it with the last digit. However the thing is that the number of rows versus columns is defined earlier in the program. So how can i do to put as many %4d as the number of rows and columns specified by a variable found before?

Thank you so much!

Subject: How to output to a file??

From: janas21

Date: 1 Feb, 2009 18:48:02

Message: 5 of 5

On Feb 1, 6:02=A0pm, "Diego Zegarra" <diego...@gmail.com> wrote:
> The spacing can be anything, it sounds good to actually align it with the=
 last digit. However the thing is that the number of rows versus columns is=
 defined earlier in the program. So how can i do to put as many %4d as the =
number of rows and columns specified by a variable found before?
>
> Thank you so much!

another way,

maybe is:

fid=3Dfid=3Dfopen('xxx.txt','w');

for i=3DProcessingSequence{1}:ProcessingSequence{3}
    fprintf(fid, '%4d %4d %4d %4d \n',i);
end
fclose(fid);

Tags for 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