Creating a Matrix with Datenum column and a string column.
Mostra commenti meno recenti
Hello,
I would like to know how to deal with this issue, I cant seem to find a proper answer.
I have the following matrix :
[735859] 'Joint'
[735901] 'Single'
[735950] 'Joint'
[735992] 'Single'
[736041] 'Joint'
[736083] 'Single'
[736132] 'Joint'
[736174] 'Single'
[736224] 'Joint'
[736265] 'Single'
[736314] 'Joint'
The first column is a datenum and I want to create a matrix without the brackets for the first column and the second column as it is.
So I did the following :
>> CL = [cell2mat(Cal1(:,1)), cellstr(Cal1(:,2))]
I would expect it would remove the brackets and keep the string column.
(Removing the brackets will permit me to use datestr...)
But the answer I get is
Error using horzcat Dimensions of matrices being concatenated are not consistent.
The dimensions are identical for me...
Can someone enlightened me please?
Thank
Davin
Risposta accettata
Più risposte (1)
Peter Perkins
il 17 Set 2014
Davin, as others have said, you have a cell array. That's one way you can store data of different types in one array, but it may not be the most convenient way.
An alternative, if you are using MATLAB R2013b or later, would be to use a table, and maybe also a categorical array. For example
>> c = {[735859] 'Joint'
[735901] 'Single'
[735950] 'Joint'
[735992] 'Single'
[736041] 'Joint'
[736083] 'Single'
[736132] 'Joint'
[736174] 'Single'
[736224] 'Joint'
[736265] 'Single'
[736314] 'Joint' };
>> t = cell2table(c,'VariableNames',{'Date' 'Type'});
>> t.Type = categorical(t.Type)
t =
Date Type
__________ ______
7.3586e+05 Joint
7.359e+05 Single
7.3595e+05 Joint
7.3599e+05 Single
7.3604e+05 Joint
7.3608e+05 Single
7.3613e+05 Joint
7.3617e+05 Single
7.3622e+05 Joint
7.3627e+05 Single
7.3631e+05 Joint
>> t(t.Date>datenum('1-Feb-2015') & t.Type=='Joint',:)
ans =
Date Type
__________ _____
7.3604e+05 Joint
7.3613e+05 Joint
7.3622e+05 Joint
7.3631e+05 Joint
Hope this helps.
Categorie
Scopri di più su Dates and Time in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!