Borrar filtros
Borrar filtros

Error when using fprintf to show a string

1 visualización (últimos 30 días)
VQ
VQ el 23 de Mzo. de 2011
Hi, I want to display a cell from Excel that contains a string and I use fprintf. Here's the code:
function [] = readExcel(a)
a=input('Type the name of the .xls file:');
[num,p_hex]=xlsread(a,'A2:A100');
[distance, string]=xlsread(a,'B2:B2');
[numeric, los]=xlsread(a,'C2:C2');
c=hex2dec(p_hex);
mn=mean(c);
fprintf('\n\nThe mean value is: %.3f\n',mn);
fprintf('Distance: %.2f m.\n',distance);
fprintf('Line of sight?:%s',los);
end
When I run the code, I get this error:
??? Error using ==> fprintf Function is not defined for 'cell' inputs.
Error in ==> fprintf('Line of sight?:%s',los);
What's the problem?,Can anybody help me?
Thanks.

Respuestas (1)

Sarah Wait Zaranek
Sarah Wait Zaranek el 23 de Mzo. de 2011
The output when you call XLSREAD with two output variables returns the second output is the text fields in cell array. This means that los is a cell - if you index into the cell using curly braces (i.e. {}) you will get the contents of that cell, or the string.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by