Parentheses error with a function call

What is wrong with this function call? It's so basic but don't know what I am missing.
The error is "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."
load('mnist.mat', 'testX');
% save('testX'); commented it based on the reply I got for this question
x=testX; % testX is a 529*784 matrix
k=5; numIter=6;
[mu, cll, ill] = gmm(x, k,numIter)
% the function definition starts like this in another file
% function [mu,CLL,ILL] = gmm(x,K,numIter)

4 commentaires

Walter Roberson
Walter Roberson le 10 Mai 2021
Modifié(e) : Walter Roberson le 10 Mai 2021
That code looks okay.
save('testX'); % testX is a 529*784 matrix
Note that that save() call would save the entire current workspace to file testX.mat not just the testX matrix.
Jaya
Jaya le 10 Mai 2021
Modifié(e) : Jaya le 10 Mai 2021
Ok, I didn't know that. Now, I have kept only the following in its place but still it's the same error. I just unable to figure out where is the problem then.
And this happens irrespective of what arguments I put in the function call. Like just two of them or one of them and changing the function def accordingly.
load('mnist.mat', 'testX');
x=testX; % testX is a 529*784 matrix
k=5; numIter=6;
[mu, cll, ill] = gmm(x, k,numIter)
% the function definition starts like this in another file
% function [mu,CLL,ILL] = gmm(x,K,numIter)
Jaya
Jaya le 10 Mai 2021
Modifié(e) : Jaya le 10 Mai 2021
Oh, it's working now!!!!
Turns out this posted code excerpt was perfectly okay. Inside the function definition, there was one ) missing for one line.
Thanks for the save() suggestion.
Walter Roberson
Walter Roberson le 10 Mai 2021
I do not see any problem with the code extract that you posted.
Perhaps the error is inside gmm function .

Connectez-vous pour commenter.

 Réponse acceptée

VBBV
VBBV le 11 Mai 2021
%if true
x = load('mnist.mat', 'testX');
k=5;
numIter=6;
function [mu, cll, ill] = gmm(x, k,numIter)
Assign x directly when loading

4 commentaires

Jaya
Jaya le 11 Mai 2021
Thanks & I did this later. But the actual problem was that, as Walter suggested, a parentheses was missing on a line inside the function definition. But in any case, your answer is more neat and avoids future errors too
Walter Roberson
Walter Roberson le 11 Mai 2021
No, when you assign the result of load of a mat file you always get a struct with one field for each variable name loaded. You would need to reference x.testX to get to the data.
Jaya
Jaya le 11 Mai 2021
Modifié(e) : Jaya le 11 Mai 2021
Thanks again for the reply. What I meant in my previous answer was I did in the way you proposed in the beginning. I didn't know that VBBV's answer and your answer would give different result into x and that's why i commented like that thinking they give same x.
I didn't see any button for accepting your answer..
Walter Roberson
Walter Roberson le 11 Mai 2021
Assigning the output of load() is a good idea... it just isn't the reason you had the problem in this situation, and the change was not coded for correctly in VBBV's answer.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 11 Mai 2021

0 votes

[copying down from correct comment]
I do not see any problem with the code extract that you posted.
Perhaps the error is inside gmm function .

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by