I am using both MATLAB and LabVIEW for Lab of course of control systems engineering and I want to implement a block diagram(system) in MATLAB and also in LabVIEW
Front panel shows "time response parametric data" which contains 6 parameters fields including settling time ,but i also need settlingMin and settlingMax which are provided/shown in MATLAB by using command stepinfo but i couldn't find a way how to get these two parameters settlingMax and settlingMin in LabVIEW.
Here is MATLAB code
clc
clear all
close all
sys1=tf([10],[1 1])
sys2=tf([1],[2 0.5])
sys_series=series(sys1,sys2)
sys_feedback=feedback(sys_series,0.1)
sys=series(540,sys_feedback)
sys_cl=feedback(sys,1,-1)
step(sys_cl)
stepinfo(sys_cl)
Download link LabVIEW VI
Comparing the help for the LabVIEW VI you are using with the help for the MATLAB function it seems obvious that MATLAB's SettlingMax is the same as LabVIEW's Peak Value in the Time Response Parametric Data cluster, while SettlingMin is the minimum value of the time response signal after Peak Time.
To get the latter value it looks as if you need to:
use CD Get Time Response Data to get the time points and response signal as DBL arrays - I assume Input and Output are both 0 since you have only one signal
use Search 1D Array with the time point array and the Peak Time value to get the array index of the peak time
use Array Subset to select the part of the response array from that index onwards (leave length unwired)
use Array Max & Min to get the minimum value of this array
Related
Im trying to do some calculations in a Matlab (R2015b) Simulink function block. I use a signal that gives discrete values in 1-minute intervals.
What i want to do is store the signal values of 1 day (1440 values), convert them into a vector and input it in my Matlab function for calculation (getting time between first and last value > x). All while the simulation is running.
Unit delay, and Transport delay blocks wont work because i need all the stored values at once.
Any ideas on this are much appreciated!
Thanks!
You need to add a "To Workspace" block to your simulink diagram. Setting the options as you wish will allow you to save all the outputs in a single vector. You can select the variable's name, and the default is "simout".
Then, after running the diagram, you have the variable you want in the workspace (as if you had typed it in the console). So next, you can call your function with the argument.
I have a matrix (type:double) of size 106 x 103. The matrix represents European gridded temperature data for one timestep (a day).
For every day, I want to calculate the degree days (thermal time) for a species, based on the temperature recorded for each 'cell' (i,j element) in the matrix using a formula that I have coded in Matlab based on a sinewave approach.
So, ultimately, what I want to do is being able to apply a calculation to my matrix, that will provide individual output for each grid cell (i,j element) dependent on the temperature data that is recorded there.
I could do this with a loop, but I have to accumulate these degree days for multiple years, so I would prefer to find a way of applying the calculation to each element in a daily matrix simultaneously (and then looping through the days (matrices)).
From what I have read, you can use a cellfun if your matrix is a cell array (mine is not).
Then I was also looking at the bsxfun option, but it seems like the functions are just standard functions..like mean, max etc.
So now, I'm looking at using arrayfun in conjunction with a function I create from my algorithm to calculate degree days.
I have been trying to write a test function but Matlab keeps throwing up the same error:
I type:
function output=degreedays(x)
and Matlab throws back:
Error: Function definitions are not permitted in this context.
Can someone tell me what I'm doing wrong? Why is it not accepting the declaration of the function name?
MATLAB does not allow you to define named functions like this at the command line. You need to place your function definition in a file. MATLAB then can call that function by the name of the file - so in your case, put your function definition in a file called degreedays.m.
See the doc for more: https://uk.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html .
I'm interested in understanding the variety of zeroes that a given function produces with the ultimate goal of identifying the what frequencies are passed in high/low pass filters. My idea is that finding the lowest value zero of a filter will identify the passband for a LPF specifically. I'm attempting to use the [hz,hp,ht] = zplane(z,p) function to do so.
The description for that function reads "returns vectors of handles to the zero lines, hz". Could someone help me with what a vector of a handle is and what I do with one to be able to find the various zeros?
For example, a simple 5-point running average filter:
runavh = (1/5) * ones(1,5);
using zplane(runavh) gives an acceptable pole/zero plot, but running the [hz,hp,ht] = zplane(z,p) function results in hz=175.1075. I don't know what this number represents and how to use it.
Many thanks.
Using the get command, you can find out things about the data.
For example, type G=get(hz) to get a list of properties of the zero lines. Then the XData is given by G.XData, i.e. X=G.XData.
Alternatively, you can only pull out the data you want
X=get(hz,'XData')
Hope that helps.
how to use the "from workspace block in simulink" ?
I have tried using the from workspace block by given 10*2 matrix as input. it is appending some extra data along the data I have given .
and I have such 3 such blocks and want to know how I merge them.
Read the documentation. Simulink is time-based so the data in your From Workspace block must be as a function of time. Does your 10 x 2 matrix represent a signal as a function of time? If so, it needs to be as follows:
A two-dimensional matrix:
The first element of each matrix row is a
time stamp.
The rest of each row is a scalar or vector of signal
values.
The leftmost element of each row is the time stamp of the
value(s) in the rest of the row.
10 values isn't very much, it's likely that Simulink will need additional data points at intermediate times, if you have the Interpolate Data check box ticked. If not, "the current output equals the output at the most recent time for which data exists".
I think you may have a misunderstanding of the variables intended to be read by the FromWorkspace block.
The block expects a time series defining the value at various points in the simulation.
The From Workspace block help should point you in the right direction on this. Mathworks Help Documentation
I believe that something like the following would work for you:
>> WorkspaceVar.time=0;
>> WorkspaceVar.signals.values=zeros(10,2)
>> WorkspaceVar.signals.dimensions = [10,2]
I have a question.
After simulate a simulink model I need to get signal dimensions of each line using MATLAB command.
I get line handles by following
line_h = find_system(gcs, 'FindAll', 'on','SearchDepth', 1, 'Type', 'Line')
then how can I get signal dimensions from line handles
** When check 'signal dimensions' in Format menu -> Port/Signal Displays
After simulate a model number of signal dimensions will show on nonscalar line.
I need to get it using MATLAB command.
Sorry for my English skill
Thank you
Alternatively, you can find the signal dimensions and signal widths of each block they originate from, using:
get_param(<block_path>,'CompiledPortDimensions')
get_param(<block_path>,'CompiledPortWidths')
Replacing <block_path> with the appropriate block path for each block of interest. The model must be compiled before you can run these commands, but since you indicate doing this after running the model, that shouldn't be a problem.
If you have a set of line handles from your find_system command you can use the following command to get the block connected to the signal.
hblkSrc = get_param(h(k),'SrcBlockHandle');
You can then use get_param(hblkSrc,'CompiledPortDimensions') as suggested by am304 to get the dimensions.
You can solve it the following way.
Enable signal logging for the desired signals (Properties). For
example set the name to custom and signalone.
If you actually don't want to log the signal, set Limit data points to last to 1, so you avoid storing unused data.
Go to SImulink preferences and enable signal logging, default output name is logsout
after simulation you'll get a dataset logsout in your workspace
now evaluate this dataset as follows:
% returns data, if data limit is set to 1 it's a coloumn
% vector with just the last value
data = logsout.get('signalone').Values.Data
you can now just use the size of this vector and you know the dimension of the signal
[~,dim]=size(data)
or in one line:
[~,dim]=size(logsout.get('signalone').Values.Data)
If you have a a lot of signals and you want to evaluate them at once, give your signals convenient output-names and use a loop for iterating through a string vector with all your signal names.
As you say you want the dimensions of "all" (are you sure?) signals I think it is more convenient to just check "Enable signal logging" in each signal property and do all further definitions in the Simulink preferences where you have a list to manage all signals.