How do I display a character string array next to a data array?

Hello, I am a Matlab noob and I need some help. I wrote this function below to add a random offest to a row vector from -L:L. I had to evaluate this value in several different functions and present the data from each function next to the name of the function. So I made a string containing the names of the functions, but I don't know how present the data next to the function name. Sorry if this doesn't make much sense, but here is my code:
function F = hw5(L) intval = [-L:L] for k = 1:(2*L+1) offset = rand-0.5; val(k) = intval(k) + offset; end offset = val - intval val
x1 = floor(val); x2 = ceil(val); x3 = fix(val); x4 = round(val); x5 = int32(val); x6 = uint32(val); x7 = single(val); x8 = sin(val);
b = ['Floor ',; 'Ceil ',; 'Fix ',; 'Round ',; 'Int32 ',; 'Uint32 ',; 'Single ',; 'Sin ',];
a = [x1 , x2 , x3 , x4 , x5 , x6 , x7 , x8 ];
end

 Respuesta aceptada

dpb
dpb el 18 de Feb. de 2014
Editada: dpb el 19 de Feb. de 2014
doc num2str
doc sprintf
etc., ...
One way...
>> b = {'Floor '; 'Ceil '}; % use a cell array for convenience in defining
>> x=rand(2,1); % some numeric values to associate with...
Now make a cell array suitable for framing...
>> cellstr([char(b) num2str(x,3)])
ans =
'Floor 0.815'
'Ceil 0.906'
>>

2 comentarios

Excellent, thanks a ton! num2str helped me concatenate both matrices perfectly. We haven't really gone through cell arrays much, but I will be sure to figure them out.
NB that one can also write stuff w/ sprintf and friends using formatting expressions altho num2str is quite handy indeed as an aid...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 18 de Feb. de 2014

Comentada:

dpb
el 19 de Feb. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by