Script of importing data not working with no warning or error

Hello
I am trying to import an excel data by using a ready script,
The problem is when i run it in editor it does not do anything!
and do not uppload the data
Where as when i change the script into a simple commande it works
No warning, no error !

 Réponse acceptée

Star Strider
Star Strider le 2 Jan 2024
The function does not produce any outputs.
You will need to declare:
global ExperimentalIVData
in your calling script to get it to work.
However, I definitely do not suggest using global variables.
Change the script to return ‘ExperimentalIVData’ as an output instead, so the initial function declaration will be:
function ExperimentalIVData = LoadExperimentalIVData
and the problem solves itself. And delete all the global calls.
.

6 commentaires

what about struct() command
Should i delete it with global calls ?
You can keep the structure representation. Just output the structure as I outlined, then refer to the structure fields as you would any other structure.
I suggest not using xlsread however. By 2020a, you should have access to the readmatrix function (introduced in R2019a). An alternative to exporting the result as a structure could be something like this, using a table:
function [ExperimentalIVData,T,S] = LoadExperimentalIVData
xlsfile = 'Data/12-01-2008/12-01-2008 12_50_04.XLS';
Ipv = readmatrix(xlsfile, 'Range','B12:B112');
Vpv = readmatrix(xlsfile, 'Range','A12:A112');
Ppv = readmatrix(xlsfile, 'Range','C12:C112');
T = readmatrix(xlsfile, 'Range','B2:B2');
S = readmatrix(xlsfile, 'Range','B3:B3');
ExperimentalIVData = table(Ipv,Vpv,Ppv);
end
The last two outputs, ‘T’ and ‘S’ will not work as part of the table (I have no idea what they are, however they are not the same sizes as the other elements, so they cannot be included in the table), and have to be returned separately.
There is nothing wrong with using the structure (although I would use readmatrix rather than xlsread). I am simply suggesting the table as an alternative. It might make things easier for you.
Thank you this is very helpful in 2020 version
But unfortunately i am using matlab 2011 because the imported data are used in Co-simulation with PSIM (SIMCOUPLER) whch is not availble in 2020 for free !
And the structure readmatrix is not availble in 2011 version
using Struct() command present a drawback that i can't understand : when the data are structures in the workspace (see attached compared with the previous photo)
It is not recognized in the command windows and therefore not recognized by the simulink.
As always, my pleasure!
You will need to use the original struct (structure) version of your function with R2011, not the table version, since table arrays did not exist before R2013b, and there have been several upgrades to them since.
To get the information from the function, call it as either:
[ExperimentalIVData,T,S] = LoadExperimentalIVData % ‘table’ Version
for the table version, or:
ExperimentalIVData = LoadExperimentalIVData % ‘struct’ Version
for the struct version.
To get ‘Ipv’ (and the rest of them, as appropriate), for the both versions is:
Ipv = ExperimentalIVData.Ipv; % Both Versions
Getting ‘T’ and ‘S’ is slightly different. For the table version, they already will exist in the workspace, using the first (% 'table' Version) call to the function.
For the strructure version, getting them is:
T = ExperimentalIVData.T; % ‘struct’ Version
and so for the rest.
Please post back if you are having any other problems with this.
.
Thank's Sir
Since i am using the imported data in an algorithm & simulink i have to call these variables without tapping anything in command window (variables should appear in workspace just when running the loadExperimentalIVData.mfile ).
Two problems appears:
First: i delete struct comand from the function but still data is in structure in workspace, rather i want each one to be alone.
Second: when i avoid using global variables but data remain local & as consequence it can't be called again (for exemple: simulink can't regognize the variable 'S' & 'T' when calling it from workspace ! )
As always, my pleasure!
I did not initially know that you wanted to import your spreadsheet data into Simulink.
Reviewing the R2020a documentation (that fortunately still exists), I was able to find the From Spreadsheet block that may be what you need to import your Excel data. I am otherwise not certain how to import your data into Simulink.
I have Simulink, however I rarely use it now, although I have used it extensively, most recently a couple decades ago. I have never needed to import spreadsheet data into it.

Connectez-vous pour commenter.

Plus de réponses (1)

Dyuman Joshi
Dyuman Joshi le 2 Jan 2024
Modifié(e) : Dyuman Joshi le 3 Jan 2024
"The problem is when i run it in editor it does not do anything!"
Because there is no output defined for the function.
There are differences to how scripts and functions work - Scripts vs. Functions
You do not need to use global here. Remove that line and modify the function to provide the variable ExperimentalIVData as the output from the function.
And use readtable/readmatrix instead of the deprecated xlsread().

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by