Hello,
I am running a matlab code which writes output to an excel file.
I would like to write * each output value inside a parenthesis * . Is there an easy way to do this?
Code I use:
results = zeros(5,10);
for i = 1:10
results(1,i)= avxt(i);
results(2,i)= stdxt(i);
results(3,i)= avxtl(i);
results(4,i)= stdxtl(i);
results(5,i)= afxtPI(i);
end
xlswrite('output.xlxs', results, 'sheet1', 'A1:H5'
Thanks.

 Réponse acceptée

dpb
dpb le 24 Avr 2014

1 vote

results = zeros(5,10);
results(1,:)= avxt;
...
etc., etc., ...
You will need a .' to transpose if they're column rather than row vectors, of course.
What sort of precision do you want/need in the spreadsheet? Writing the values as numeric stores the full precision automagically whereas if you convert to string to show the parens you'll have to select some formatting.
Then place the result to a cell array after using sprintf() to output the desired format.
>> sprintf('(%.3f)',pi)
ans =
(3.142)
>>
doc sprintf % for details.
NB you will have to write each element to a cell. cellfun should be useful here

3 commentaires

dav
dav le 25 Avr 2014
Thanks. Well I tried the following code to do a table in matlab and it gave me the given error: Is there anyway to correct it please?
results = zeros(5,h);
for i = 1:h
results(1,i)= avxt(i);
results(2,i)= stdxt(i);
results(3,i)= avxtl(i);
results(4,i)= stdxtl(i);
results(5,i)= afxtPI(i);
end
results
pnt1 = sprintf('(%.4f)',results(2,1));
pnt2 = sprintf('(%.4f)',results(4,1));
pnt3 = sprintf('(%.4f)',results(2,10));
pnt4 = sprintf('(%.4f)',results(4,10));
pnt5 = sprintf('(%.4f)',results(2,20));
pnt6 = sprintf('(%.4f)',results(4,20));
cov = [val1;pnt1;val2;pnt3;val3;pnt5];
len = [val4;pnt2;val5;pnt4;val6;pnt6];
Tbl = table(cov,len)
Error:
Error using vertcat
CAT arguments dimensions are not consistent.
Error in prnt (line 470)
cov = [val1;pnt1;val2;pnt3;val3;pnt5];
cov = {val1;pnt1;val2;pnt3;val3;pnt5};
len = {val4;pnt2;val5;pnt4;val6;pnt6};
dav
dav le 25 Avr 2014
thanks. I think it worked. However I got the following error. am i not using it correct?
Error:
Undefined function 'table' for input arguments of type 'cell'

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Question posée :

dav
le 24 Avr 2014

Commenté :

dav
le 25 Avr 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by