2

containers.map在 MATLAB 中使用 hashtable ( ),现在我想用该信息创建一个矩阵。因此,当我运行我的哈希表,然后为每种类型插入我的文本文件时,我会在命令窗口中看到类似这样的内容:

编辑

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');

whereE只是用户的输入,在这种情况下是pink,purpleyellow

%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'

所以我现在想将总数b作为矩阵上的行数m;所以总行数为 14 并且每一位从a成为一列;所以一共有3列。但我想创建一个二进制矩阵,其中每列将标识不同的类型。最后,我将创建一个这样的矩阵:

  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

4

1 回答 1

2

So something like this?

val = cellfun(@length, b)';

m = 0;
for v = 1:size(val)
  m(end:end+val(v)-1,v) = 1;
end
于 2013-08-14T11:10:09.610 回答