2

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

2
  • Still not entirely clear; could you explain in more detail what the keys and values in your Map are? It would be best if you could create a minimal working example where you populate the Map with values, and then explain what output you would like. Commented Aug 14, 2013 at 10:48
  • thanks.. I have just edited it, I hope I was more clear now :) Commented Aug 14, 2013 at 11:09

1 Answer 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
Sign up to request clarification or add additional context in comments.

4 Comments

@Chrysovalando Wait... I thought you were saying b is your input and m is your desired output? Is that not the case
yes that is the case.. but when I use it in my code I only get one column of 1 but if I run it as it is I get what I want.. So probably I have something crazy going on my code :/
please see now my original post :)
@Chrysovalando Try and transpose my original val calc, see my edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.