Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

5 views (last 30 days)
I got invalid expression on my code, I have no idea what I did wrong.
This is the error:
File: getCriticalValue.m Line: 10 Column: 69
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
Error in myKurtosis (line 30)
if (getKurtosis(DataSetCal, i, c1) > getCriticalValue(c1(:)))
This is the code:
function myKurtosis
A = input('Enter File Name: ', 's');
FileName = strcat(A,'.txt');
% Data needs to be cleaned first where we put only one space in between and
% split the data using delimiter
opts = detectImportOptions(FileName);
opts.VariableNamingRule = 'preserve'; % Preserve original column headers
Data = readtable(FileName, opts);
Data2 = table2array(Data);
row = height(Data2);
Outliers = [];
for i = 1:14
OutCount = 0; % Corrected typo (OutCOunt -> OutCount)
c1 = 0;
c2 = 1;
DataSetCal = zeros(15, 14); % Initialize DataSetCal
for j = 1:row
% Add data to a dataset to be checked for kurtosis calculation
c1 = c1 + 1;
DataSetCal(c1, i) = Data2(j, i); % Assuming each column contains the data for one variable
% Calculate kurtosis value
kurtosisVal(j, i) = getKurtosis(DataSetCal, i, c1);
% Compare the kurtosis value with the critical value stored and remove data if exceeded
if (getKurtosis(DataSetCal, i, c1) > getCriticalValue(c1(:)))
OutCount = OutCount + 1;
Outliers(OutCount, i) = Data2(j, i);
c1 = c1 - 1;
else
% Store value of kurtosis that will be used for visualization
% of data with outliers removed
NewKurtosis(c2, i) = kurtosisVal(j, i);
end
end
% Used to find end limit for visualization purposes
NewKurtosis(c2, i) = -1;
end
save 'New'
end
  3 Comments
John D'Errico
John D'Errico on 31 Mar 2024
This is what you show as the error message:
File: getCriticalValue.m Line: 10 Column: 69
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
Error in myKurtosis (line 30)
if (getKurtosis(DataSetCal, i, c1) > getCriticalValue(c1(:)))
What does that mean? The error was seen in the function myKurtosis, but it does not actually happen there. The actual error happens in line 10 of the function getCriticalValue, where there is an invalid expression. But you don't show that function.
Voss is correct. Show that code.

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!