Question

1) I have 5 data which save in note pad, only data4 have the word 'Form', however it appear 4 times in my results which show that it occur (e.g.: C9=[1 1 1 1]). How would I modify it to only C9=[1]. Then the overall results include data1 until data5 would be C9=[0 0 0 1 0]

data1=<form name="yahoo" method="post" action="yahoo.php">
data2=n/a
data3=<form>
data4=<form name="yahoo" method="post" action="yahoo.php" onsubmit="return ValidateFormYahoo()">

data5=onsubmit="return ValidateFormYahoo()"

Now my code:

 A9 = {'Form'};%check domain
 D9 = {'Validate'};%check domain

data1=  importdata('f9_data1');
data2 = importdata('f9_data2');
data3 = importdata('f9_data3');
data4 = importdata('f9_data4');
data5 = importdata('f9_data5');


C9_data1=any(cellfun(@(n) ~isempty(n), strfind(data1, A9{1}& D9{1})))
C9_data2=any(cellfun(@(n) ~isempty(n), strfind(data2, A9{1}& D9{1})))
C9_data3=any(cellfun(@(n) ~isempty(n), strfind(data3, A9{1}& D9{1})))
C9_data4=any(cellfun(@(n) ~isempty(n), strfind(data4, A9{1}& D9{1})))
C9_data5=any(cellfun(@(n) ~isempty(n), strfind(data5, A9{1}& D9{1})))

E9=[C9_data1;C9_data2;C9_data3;C9_data4;C9_data5]

I want to check is that 'form' & 'validate' occur at the same time, then return 0, also if nth then return 0, else if only 'form' or 'validate' then return 1 [data1 data2 data3 data4 data5]=[1 0 1 0 1]

Was it helpful?

Solution

If you just want to aggregate into one value, you can say this:

C9=any((cellfun(@(n) ~isempty(n), strfind(data4, A9{1}))));

The any function returns true if any of the values in the input array is not zero.

For the second question, if you used any, the result is boolean value (true or false), then you can just do a logical AND.

C9=any((cellfun(@(n) ~isempty(n), strfind(data4, A9{1})))) && any((cellfun(@(n) ~isempty(n), strfind(data4, D9{1}))));

However, I'm not sure what your data file is and what you are trying to say. The importdata function most often returns a structure with multiple fields, and the strfind function operates on either a string or a cell array of strings, but not structures. So the reason you get a vector as output puzzles me. It might help if you describe your input data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top