Dr. Turkuaz
Dr. Turkuaz

Reputation: 39

How to write the results to output file (preferably excel) for each run

I have a simple matlab code using transition matrix and doing monte carlo simulation. I have attached the code.

What I need you to do is: Write the results of each run in excel with the changing pattern size. The code just write the last numbers as usual. I would like to see each run results for an array called "pattern". For example "pattern" will be like this (Assuming that t=3 and;

Run1--- 45 12 17 17 17
Run2--- 56 24 24
Run3--- 7  45 45 21

In the matlab code below: pattern: Visit pattern to company, say customer visited company 2 then company... , so the pattern 2-3... Pr: Number of times company i visited Seq: Number of times company sequential visits to company i [Here is the transition matrix excel]

   clear all;
   clc;
   t=10;
      for ii=1:t
      .
      %(The codes created the pattern array)
      .
          filename=('output1.xlsx');
          xlswrite(filename,pattern,sheet1,'B2:NT2');

       end

When I use the code it gives me only the last result when ii=3;

         Run3--- 7  45 45 21

It does not have to be excel, other output file will be ok too. I tried to use sprintf but it does not work.

Thank you in advance.

Upvotes: 0

Views: 87

Answers (1)

Adriaan
Adriaan

Reputation: 18177

What you can do is create a string using sprintf:

SheetRange = sprintf('B%i:NT%i',ii+1,ii+1);
xlswrite(filename,pattern,sheet1,SheetRange);

sprintf writes a string with the specified format, in this case 'B%i:NT%i', where the %i denotes an integer should go there. Since you specify %i twice, you need two integers to go into the string, hence the ii+1,ii+1.

And of course, as always: consider not using i as a variable name

Upvotes: 1

Related Questions