Effacer les filtres
Effacer les filtres

Code problem in matlab

2 vues (au cours des 30 derniers jours)
Israt Jahan
Israt Jahan le 6 Déc 2016
Commenté : Israt Jahan le 6 Déc 2016
Hi
I have two matrix like
B=[0 1 1.1 1.2]
H=[0 10 12 15]
I rearrange it like
x=[0 0
10 1
12 1.1
15 1.2]
In one matlab file.
Now i want to get output like
{'0' '0'; ...
'10' '1'; ...
'12' '1.1'; ...
'15' '1.2'};
So i have written matlabcode in another file like
cellfun( @(x) num2str(x, '%0.10g'), num2cell( [H',B'] ), 'UniformOutput', false)
But it did not give me desired result as i expected.
Anyone can help me about that.
Thanks in advance
  2 commentaires
Geoff Hayes
Geoff Hayes le 6 Déc 2016
Israt - when I run your code, I observe the following result
>> cellfun( @(x) num2str(x, '%0.10g'), num2cell( [H',B'] ), 'UniformOutput', false)
ans =
'0' '0'
'10' '1'
'12' '1.1'
'15' '1.2'
which is a cell array of strings (where each string is converted from the numbers in your concatenated arrays). This seems very similar to your desired output. What are you expecting instead?
Israt Jahan
Israt Jahan le 6 Déc 2016
thanks. i made littele mistake. now it works

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 6 Déc 2016
What about this:
x = [0, 0; ...
10, 1; ...
12, 1.1; ...
15, 1.2];
c = sprintfc('%g', x);
Unfortunately this useful function is not documented.
  1 commentaire
Israt Jahan
Israt Jahan le 6 Déc 2016
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by