How to store input and output arguments in a matrix form so that it can be exported to EXCEL?

1 view (last 30 days)
Hello everyone, I have a function that gets 8 inputs and returns 8 outputs. I want to store all these arguments and intermediate results in a matrix and export them to EXCEL sheet. I got the syntax for text but could not store the arguments (numbers) in matrix.
function [a, b, c, d, e, f, g, h] = ConcWtXls (R, S, T, U, V, W, X, Y)
%main code goes on here
A{1,1} = 'Text1';
A{1,2} = 'Input';
A{1,3} = 'Intermediate Result';
A{1,4} = 'Output';
A{2,1} = 'Text2';
A(2,2) = '%.4f', R;
A(2,3) = '%.4f', iv;
A(2,4) = '%.4f', a;
%similarly the code goes on for remaining inputs and outputs
xlswrite('Samplefile.xls',A);
end
The above piece of code shows error as
Conversion to cell from char is not possible.
Error in ConcWtXls (line 154)
A(2,2) = '%.4f',icNaCl;
The input and output arguments are all numerical values.

Accepted Answer

Stephen23
Stephen23 on 22 Jul 2018
Edited: Stephen23 on 22 Jul 2018
This is not valid MATLAB syntax:
A(2,2) = '%.4f', R;
You will need to use curly braces to allocate to the cell array, and specify sprintf:
A{2,2} = sprintf('%.4f',R);
MATLAB is not Python, so you need to read the MATLAB documentation to know how to use MATLAB.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!