Reputation: 97
I am using hashtable (containers.map
) in MATLAB, and now I want to create a matrix with that information. So when I run my hashtable and then insert my text files for each type I get on my command window something like that:
edit
F = listdlg('PromptString','Different types', 'SelectionMode',...
'single', 'ListString',E, 'Name','Select a type','ListSize',[230 130]);
[files,path] = uigetfile ('*.txt','Select your text files',...
'MultiSelect','on');
where E
is just the user's input which in this case is pink
, purple
and yellow
.
%save for each type the user enters the corresponding text files he
%wants to train
%A Map object is a data structure that allows you to retrieve values
%using a corresponding key. Keys can be real numbers or text strings
%and provide more flexibility for data access than array indices,
%which must be positive integers. Values can be scalar or nonscalar arrays.
handles.map (E(F,:)) = files;
handles.map
a = handles.map.values
b = handles.map.keys
handles.map.size
b =
{1x3 cell} {1x6 cell} {1x4 cell}
a =
'pink ' 'purple' 'yellow'
So I want now to the the total number of b
to be the number of rows on my matrix m
; so a total number of rows 14 and each bit from a
to be a column; so a total of 3 columns. But I want to create a binary matrix where each column will identify different type. Finally I will have created a matrix like that:
m =[1 0 0
1 0 0
1 0 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 0 1
0 0 1
0 0 1
0 0 1];
Where the first 3 rows of the matrix says that there are 3text files of type pink
, the next 6 rows : 6 text files of type purple
and the last 4: 4 text files of type yellow
.
I hope that now is more clear. :)
Any help would be appreciated! :) x
Upvotes: 2
Views: 374
Reputation: 45752
So something like this?
val = cellfun(@length, b)';
m = 0;
for v = 1:size(val)
m(end:end+val(v)-1,v) = 1;
end
Upvotes: 2