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

 採用された回答

dpb
dpb 2014 年 2 月 18 日
編集済み: dpb 2014 年 2 月 19 日

0 投票

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 件のコメント

Isaiah
Isaiah 2014 年 2 月 19 日
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.
dpb
dpb 2014 年 2 月 19 日
NB that one can also write stuff w/ sprintf and friends using formatting expressions altho num2str is quite handy indeed as an aid...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Structures についてさらに検索

製品

質問済み:

2014 年 2 月 18 日

コメント済み:

dpb
2014 年 2 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by