Declrarion of an array using tilde (~). what is the correct way of using it, because my code prompts me incorrect use of tilde.

4 vues (au cours des 30 derniers jours)
this part of my code that genrate the error
[~, i] == max(y);
if i == D(k)
acc = acc + 1;
end

Réponse acceptée

GandaBerunda
GandaBerunda le 16 Juin 2022
Hi Abraham,
Instead of an assignment, you are performing a comparison in the line [~,i]==max(y). For assignment, a single = symbol suffices.
Hope it clears your issue.

Plus de réponses (1)

John D'Errico
John D'Errico le 16 Juin 2022
Modifié(e) : John D'Errico le 16 Juin 2022
This is a test:
if i == D(k)
It is the correct way to use == because == is a comparison operator.
However, this other line is an assignment. That is, you are calling the function max, and returning a result in the variable i.
[~, i] == max(y);
The error mesage about ~ that you report is confusing to you. The problem is, MATLAB was also confused, because you used invalid syntax there. So MATLAB generated whatever error it could. The correct syntax to perform an assignment uses a SINGLE = operator, thus:
[~, i] = max(y);

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by