Effacer les filtres
Effacer les filtres

Problem in special characters

10 vues (au cours des 30 derniers jours)
YASSER
YASSER le 26 Fév 2024
Commenté : Voss le 28 Fév 2024
Dear all;
I have a ready code contain this command within a function
---------------------------------------------------
[pvdata,~]=xlsread([Newfolder, Mono70W999]);
when i lunch it an error appear ( tha path and the file names are correct)
Unrecognized function or variable 'Newfolder'.
Error in PVModuleCurveFitting/Open (line 85)
[pvdata,~]=xlsread([Newfolder, Mono70W999])
Error while evaluating UIControl Callback.
  • I uhave problem understaning the use of square brackets in xlsread because i used to work with these syntax
num = xlsread(filename)
num = xlsread(filename,sheet)
num = xlsread(filename,xlRange)
num = xlsread(filename,sheet,xlRange)
num = xlsread(filename,sheet,xlRange,'basic')
[num,txt,raw] = xlsread(___)
  • also i want to know the purpose of using ~ alone ?

Réponse acceptée

Voss
Voss le 26 Fév 2024
Modifié(e) : Voss le 26 Fév 2024
1. The error, "Unrecognized function or variable 'Newfolder'." means that the variable 'Newfolder' is not defined in the function that's calling xlsread, at the time xlsread is called.
2. The square brackets construct a file name by horizontally concatenating the variables 'Newfolder' and 'Mono70W999'. Example:
Newfolder = 'C:\Data';
Mono70W999 = 'Project1.xlsx';
result = [Newfolder, Mono70W999]
result = 'C:\DataProject1.xlsx'
Then that file name is passed to xlsread as the only input, so this is using the "num = xlsread(filename)" syntax.
Note that fullfile is better than square brackets for constructing file paths because it inserts directory separators between its arguments as needed. Example:
result = fullfile(Newfolder, Mono70W999)
result = 'C:\Data/Project1.xlsx'
[MATLAB Answers runs on a Linux platform,which uses slash ( / ) so that's why that's there. If you run it in Windows you'd get a backslash ( \ ) instead.]
3. The purpose of ~ is to indicate that the second output from xlsread is discarded. In this case, the ~ is unnecessary because the first output of xlsread is the same regardless of how many outputs are requested, so you'd get the same behavior with out = xlsread(filename) syntax.
Some other function besides xlsread might output different things depending on how many outputs are requested, in which case the [out1,~] = func(in) syntax might be necessary.
  14 commentaires
YASSER
YASSER le 28 Fév 2024
Thank you Mr Voss
Thank you all of you
Voss
Voss le 28 Fév 2024
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by