Good morning,
I want to ask you about an iddata object in Matlab. I want to know how it is possible to check its values (the y1 output). This is my code:
data = iddata(M4,M4,0.01);
sys = arx(data,[4 1 1])
K=6;
hf2=forecast(sys,data,K);
And I want to know the values of the forecast output, the 'hf2' (but it is an iddata object and I don't know how to do it). I have seen that I can plot it but I don't know how to know the values.
Thanks in advance,
The function properties allows you to displays the names of properties of a matlab object. Then you can access the propertie's value with the command: object.properties.
For example: hf2.OutputData
Also read the doc about the object iddata, all the properties are explained.
Related
To save the time, I'm trying to read the .mat file rather than simulate the model again.
I used scipy.io.loadmat but it didn't work well:
res = loadmat('ChatteringControl_result.mat')
res.keys()
['Aclass', 'dataInfo', 'name', 'data_2', 'data_1', 'description']
The keys are not variable names, and I don't know how to get the variable values.
Then I searched for resolutions, and found DyMat, it works well for other variables but cannot get time.
res1 = DyMat.DyMatFile('ChatteringControl_result.mat')
T = res1['T']
t = res1['time']
KeyError: 'time'
So, how can I get all the results in JModelica?(Without open Matlab of course.)Like, a built-in function in JModelica?
BIG THANKS!
To load the mat file using JModelica you can use this code:
from pyfmi.common.io import ResultDymolaBinary
res = ResultDymolaBinary("MyResult.mat")
var = res.get_variable_data("myVar")
var.t #Time trajectory
var.x #Variable trajectory
https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/technical_details.html#the-matv4-result-file-format describes the format. I think you can also look in a Dymola manual for more details.
As for DyMat, there is no reason to get the time trajectory because you typically lookup what value a variable has at a certain time. The start and stop-times are in the data_1 matrix as far as I remember (or typically get it from the first trajectory in the data_2 matrix). (The data_2 matrix may be interpolated, so the time values stored in it may not reflect the actual steps taken internally by the solvers)
I have a myfile.mat that contains 3000x35 size data. When I load it into a variable as :
a = load('myfile.mat')
It gives struct of size 1x1 . How can I get exact form as matrix. This is required because I need to change certain column values.
(This answer is valid for MATLAB, I am not sure it works exactly the same way in Octave)
You have several options:
Option 1:
If the .mat file only contains one variable, you can do:
a = struct2array(load('myfile.mat')); % MATLAB syntax
a = [struct2cell(load('myfile.mat')){:}]; % Octave syntax
Option 2:
You need to know the name of the variable at the time of saving, which is now a name of a field in this struct. Then you would access it using:
a = load('myfile.mat'); a = a.data;
Option 3 (unrecommended!):
Just remove the a = part of the expression,
load('myfile.mat');
Then the variables inside this file will "magically spawn" in your workspace. This is not recommended because it makes it difficult (impossible?) to see when certain variables are created.
I found the solution myself. I did like this
a = load('myfile.mat')
a = a.data
So that now I can access values of a as matrix with indexing, a(1,2) like this.
It is in octave. I hope it is similar in matlab.
Mathworks has done it again: my ancient R2012 (as bestowed by my company) returns a nice set of doubles identifying the figure window numbers in response to
currhandles=findall(0,'type','figure');
Now I got a fellow remotely IM-ing me 'cause the code I gave him fails under R2015 because findall now returns a structure for the figure handle. I can't play w/ his system (no RDC) and the mathworks documentation pages don't appear to specify the elements of the figure handle structure. In particular, I'd like to know if I can still retrieve the figure window number. Anyone know?
Of course.
currhandles(:).Number
will return all numbers as a comma-separated list.
Or specify a number you want:
currhandles(1).Number
The order appears to be the inverse order of initialization.
Alternatively you can define two anonymous functions to get an array directly:
figure(1); figure(2); figure(42);
getNumbers = #(x) [x.Number];
getFigureNumbers = #() getNumbers([findall(0,'type','figure')]);
getFigureNumbers()
ans =
42 2 1
let us suppose that we have following graph of singular value distribution
which was given by following command
stem(SV)
SV_singular values,from visually of course we can find approximate values of singular values,but is there any possibility to get values from graph itself?of course someone may say that if we have SV,we can directly access,but i want just graphicl tool to get it from picture itself,for example like this
b=stem(SV);
but when i type b,i am getting following number
b
b =
174.0051
it is matlab self learning,so please help me to learn how to find values from graphics in matlab
The value stored in your variable b is a handle to the current axes. You can access the properties of this axes using get. To access the values in the plot, you can use
b=stem(SV);
values = get(b, 'ydata');
For classification I'm building a number of models for a classifier in MATLAB. I use the class ClassificationKNN for this.
I would very much like to store multiple models (or objects of this class) inside a matrix.
Normally you could access and create matrices inside a matrix with the curly braces ({}).
My loop looks like this:
models = []
for i = 1:length(x)
models = [models, {ClassificationKNN.fit(x,y)}]
end
Unfortunately this returns a matrix models of size (1,3) but all cells are empty which means the models are lost...
How can I make sure every model is stored in a matrix? I need to do this because I need all models later in my calculations and the position in the matrix is important...
Any ideas?
You want a cell array of models, right? It sure looks that way, if that will work try this:
models = {}
for ii = 1:length(x)
models = [models, {ClassificationKNN.fit(x,y)}]
end
Also, you loop through calling ClassificationKNN.fit(x,y) with the same arguments every time, is this just a test, or pseudo-code for an example. Like the comment says, it's best to preallocate like:
models = cell(length(x),1);
for ii = 1:length(x)
models{ii} = ClassificationKNN.fit(x,y);
end
But, either way is likely fine.
Thanks to macduffs post I finally figured out what was going on. Whilest reading his proposition I realised that that indeed should be the correct way if getting a cell array of objects.
After trying it, the array again seemed empty when opening it in the variable editor. I tried calling the first cell in the array to see if it was indeed empty and it was not. It returned the object I had stored in it. This means the question was answered.
I then reverted back to my own method to see if that worked as well and it did. When calling a cell it also returned an object.
Bottom line:
Do not trust the variable editor ^^.