Effacer les filtres
Effacer les filtres

I want my function to return -1 when the file doesn't open.

1 vue (au cours des 30 derniers jours)
Irfan Ibrahim Yeniceri
Irfan Ibrahim Yeniceri le 2 Avr 2022
Commenté : Voss le 2 Avr 2022
I want my function to return -1 when the file doesn't open. But this happens

Réponse acceptée

Voss
Voss le 2 Avr 2022
Your code is explicitly throwing the error, here:
error('error opening file %s\n',fname);
You can remove that line (and the next one because there is no need to close a file that's not open), so that that part looks like this:
if fid < 0
charnum = -1;
return
end
Then the function will return -1 in that case.
  2 commentaires
Irfan Ibrahim Yeniceri
Irfan Ibrahim Yeniceri le 2 Avr 2022
Thank you so much. I have been dealing with this for hours. I removed each one individually but i didn't try to removed them both. Thank you again.
Voss
Voss le 2 Avr 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (1)

Riccardo Scorretti
Riccardo Scorretti le 2 Avr 2022
Modifié(e) : Riccardo Scorretti le 2 Avr 2022
Hi. You must return just after assigning the value -1 to charnum. If you call the function error... well, you get an error message and the program stops. Use warning instead.
if fid == -1
charnum = -1;
warning('error opening file %s', fname);
return
end

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by