How will i correct this error?

In this above mentioned blog, it has the code of what i have done. In that code, the below mentioned code of lines when executed showed the error :
Attempt to reference field of non-structure array.
Error in @(x)length(x.freqSets)
Below is the mentioned code:
minSup = 0.6; % minimum support threshold 0.6
[F,S] = findFreqItemsets(transactions,minSup);
fprintf('Minimum Support : %.2f\n', minSup)
fprintf('Frequent Itemsets Found: %d\n', sum(arrayfun(@(x) length(x.freqSets), F)))
fprintf('Max Level Reached : %d-itemsets\n', length(F))
fprintf('Number of Support Data : %d\n', length(S))
I have created a file named findFreqItemsets in the same path, which includes the following code.
%findFreqItemsets() generates frequent itemsets using the Apriori method.
function [F,S,items] = findFreqItemsets(transactions,minSup,oneItemsets)
F = -999999; % Default to -999999.
S = -1; % Default to -1.
items = []; % Default to null.
% Remainder of code follows...
%FINDFREQITEMSETS generates frequent itemsets using Apriori method
% |transactions| is a nested cell array of transaction data or a table
% with |Value| column that contains such cell array. Each row contains a
% nested cell array of items in a single transaction. If supplied as a
% table, it also needs |Key| column with a cell array of transaction ids.
%etc
What was wrong with this code? How do i correct my error?

3 Kommentare

Image Analyst
Image Analyst am 19 Dez. 2015
I fixed your formatting for you this time, but please be kind to us and read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
John D'Errico
John D'Errico am 20 Dez. 2015
Please stop posting identical questions. You will not get better answers.
Walter Roberson
Walter Roberson am 20 Dez. 2015
Other volunteers: I posted a number of answers to this (and the identical question) last night, but they were all rejected by the user so I deleted them. The user needs to go back to using the code from the blog and simply send it different input, but is apparently unwilling to do so.
Every one of the outputs the user creates in their attempted code is the wrong data type: the first output needs to be a structure with a field FreqSets, the second needs to be a container.Map, and the third needs to be a cell array. Just like is computed by the code they completely replaced.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 19 Dez. 2015

0 Stimmen

Inside findFreqItemsets(), you ran through code where the return value of F never got assigned. It seems like the most common cause is that you had some "if" statements in there and went into a particular one where F was not assigned. The best practice is to assign ALL return variables with something as soon as you enter the function. It can be some error code like -999 or 0 or -1, or it can even be null, [], but it needs to be something.
function [F,S,items] = findFreqItemsets(transactions,minSup,oneItemsets)
F = -999999; % Default to -999999.
S = -1; % Default to -1.
items = []; % Default to null.
% Remainder of code follows....
Then, afterwards in your main program where you called this function, you can check for the default values and take appropriate action.

1 Kommentar

PARVATHY P P
PARVATHY P P am 20 Dez. 2015
I have changed it as per ur suggestions, but iam stilling getting the error

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 20 Dez. 2015

0 Stimmen

Sorry, you will need to find a different programming language to use; MATLAB is not able to handle your requirements.
You want MATLAB to treat values as simultaneously being structures and non-structures. MATLAB is not able to do that. You will need to find a different programming language that implements RPM (Read Programmers Mind), or DWIWNWIS (Do What I Want Not What I Say).

Tags

Gefragt:

am 19 Dez. 2015

Kommentiert:

am 20 Dez. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by