# How do I make MATLAB list the various sequences possible for a specific purpose?

1 Ansicht (letzte 30 Tage)
Samyukta Ramnath am 26 Jun. 2013
I need to find a way to list all the possible sequences of a sentence, for example if I have a set of 8 possible attributes of a certain word, and I have a sentence which is just a combination of words. I need to find a way to list the various possible sequence of attributes for that sentence. For example, I have the sentence 'the shark killed the man'. I know that 'the' has the attribute 'DD', and I know that the word which follows a word with attribute 'DD' has the attrbute 'NN' or 'ADJ'. So how do I get MATLAB to list the sequences : DD NN ? DD NN DD ADJ ? DD ADJ DD NN ? DD ADJ DD ADJ ? DD NN In other words, I want to say that the attribute of the second word (let's say T2) is either NN or ADJ, and the same for the fourth word (T4).
This doesn't work :
if true
% code
Tag = cell(1,size_string);
for i = 1:size_string
for j = 1:size_art
if strcmp(string(i),art{j})
disp(string(i+1));
(Tag(i+1) = 'NN') || (Tag(i+1) = 'ADJ');
disp(' ');
disp(string(i));
disp('is an article');
end
end
end
end
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Lokesh Ravindranathan am 26 Jun. 2013
I think there could be couple of issues in the code. I could not execute your code completely, since I do not have access to your variables.
You define Tag as a cell and you are trying to assign using a normal circular parentheses. You should assign variables using curly parentheses.
Tag{i} = 'NN'
would work in your case. When using logical OR operator (), you should have a lhs and rhs which could be converted of type logical type.
Even otherwise, when you are using |, in your case, you should expect the lhs and rhs of equal sizes.
In your case, I am not sure what you are expecting of your code.
##### 2 KommentareKeine anzeigenKeine ausblenden
Samyukta Ramnath am 26 Jun. 2013
I basically want it to have two possibilities, that the tag could be NN and it could also be ADJ. Should I use a matrix for this? But I also have to get MATLAB to recognize that there could be different possible tags for every word in the sentence. The number of possibilities are subject to certain rules.
Lokesh Ravindranathan am 26 Jun. 2013
You could use the cell array inside a cell array.
Tag{i}{1} = 'NN'
This will ensure you have various tags and for the count, you could simply do
numel(Tag{i}{:})

Melden Sie sich an, um zu kommentieren.

Muthu Annamalai am 26 Jun. 2013
@Samyukta you seem to need a 'generative grammar'. You can do this via mutually recursive functions. You should type the following in MATLAB and watch the program
>> for i = 1:10, why; pause(1); end
>> edit why
While my favorite demo doesn't directly solve your problem, you can definitely see how to build a generative grammar.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by