Problem in special characters

6 views (last 30 days)
YASSER
YASSER on 26 Feb 2024
Commented: Voss on 28 Feb 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 ?

Accepted Answer

Voss
Voss on 26 Feb 2024
Edited: Voss on 26 Feb 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 Comments
YASSER
YASSER on 28 Feb 2024
Thank you Mr Voss
Thank you all of you
Voss
Voss on 28 Feb 2024
You're welcome!

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!