Problem in special characters

6 次查看(过去 30 天)
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 ?

采纳的回答

Voss
Voss 2024-2-26
编辑:Voss 2024-2-26
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 个评论
YASSER
YASSER 2024-2-28
Thank you Mr Voss
Thank you all of you

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by