Problem in special characters

6 ビュー (過去 30 日間)
YASSER
YASSER 2024 年 2 月 26 日
コメント済み: Voss 2024 年 2 月 28 日
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
Voss
Voss 2024 年 2 月 28 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by