If have an array (5000x1 double) in matlab workspace. I put the 'from workspace' block in simulink window for input of another block, But when run the program this error occurred:
Invalid matrix-format variable specified as workspace input in 'new_net_pattern_recog/From Workspace'. The matrix must have two dimensions and at least two columns. Complex signals of any data type and non-double real signals must be in structure format. The first column must contain time values and the remaining columns the data values. Matrix values cannot be Inf or NaN.
What can I do?
I believe that you are getting this error because the From Workspace block is expecting your data to be in the form of a time series. According to the documentation for this block,
In the Data parameter of the block, enter a MATLAB expression that specifies the workspace data. The expression must evaluate to one of the following:
A MATLAB timeseries object
A structure of MATLAB timeseries objects
An array or structure containing an array of simulation times and corresponding signal values
It sounds like your 5000x1 element array does not change over time, and these values are intended to remain constant throughout the entirety of the simulation. If this is true, then you should just use a Constant block. To use a variable from the workspace as the output of this block, simply set the "Constant Value" parameter of the constant block to the name of your variable. Refer to this doc for more info on the Constant block.
Related
I want to run an Anylogic Parameter experiment, and I want the parameters to be read continuously from an excel file such that each row of excel data corresponds to parameters of one run. Likewise I want it to run as many times as rows of parameters in excel. I am able to read one row data using ExcelControlName.getCellNumericValue("ExcelSheetName", RowNumber, ColNumber) but how do I set it up such that it automatically runs multiple times by running parameters from all rows.
in your simulation model, create a parameter called row, and this will be the ONLY parameter that changes in your parameter variation experiment... then you will transform your parameters in your simulation to variables, and each variable will read the excel file as follows>
ExcelControlName.getCellNumericValue("ExcelSheetName", row, ColNumber)
where row, is the parameter that changes in your parameter variation experiment, and colNumber is the column representing the particular variable that you want to assess.
A very useful question.
One option is to make use of the Simulation Object and not let the model skip the experiment and run the model.
This will just give you some more control over your model execution and you can use some of the before and after simulation run code.
Image the following super-simple model
I have a single parameter and an event that traces the parameter and then stops the simulation.
Then on Experiment I have an Excel object, and a variable that is linked to the parameters on main, and a button that just calls run()
The excel file has some simple data in
Now on the experiment's Java section you only need to add the following code.
This ensures that the variable is updated with the correct data based on the run count, and that when you stop the model it will call the run function again if there is more values in the Excel sheet to load.
Note that the row index in Excel starts at 1 and that we have a header for our data so we want to start at row 2, hence I added 2 + getExperiment().getRunCount()
If you run this simple model you will see in the Console printed out the values from the Excel file.
10.0
20.0
30.0
I'm using Lee Mac's length and area field to automatically get the total length of an object.
I'm a complete beginner on AutoLisp so I cant find the variable responsible on holding the total length so I can put it in my snippet code to automatically copy it on my clipboard for easy pasting on excel.
Here's my code snippet for automatically putting it to clipboard
(vlax-invoke
(vlax-get (vlax-get (vlax-create-object "htmlfile") 'ParentWindow) 'ClipBoardData)
'setData
"TEXT"
(getvar
)
Since my application uses AutoCAD field expressions to output the length and/or area, the length & area values are not stored in any variable in the code; furthermore, the resulting values displayed by the selected annotation object (which may also be converted to other units and formatted by the field expression) are only available after the field expression has been evaluated.
Given the above, you would need to obtain the text content of the object selected for output after it has been populated with the field expression, before copying such content to the Windows clipboard.
This would involve modifying every branch of my LM:outputtext function to assign the result of evaluating the field expression to a variable which may then be returned by the function and used by the calling function.
=IF($D2="5 (Somewhat agree)",5,IF($D2="1 (Strongly disagree)",1,IF($D2="2 (Disagree)",2,IF($D2="3 (Somewhat disagree)",3,IF($D2="4 (Neither agree nor disagree)",4,IF($D2="6 (Agree)",6,IF($D2="7 (Strongly Agree)",7,IF($D2="","NA"))))))))
It looks like your values always start with the number of interest so you can just use LEFT to extract the number. The exception is the blank inputs that output . You can control the output here with a single IF to convert to NA
=LEFT(D2, 1)
You can also use VLOOKUP to import your values. Just create a reference table (see table on left below) and then reference it to output the appropriate mapping. For blanks this will return #N/A although you can control the error output by wrapping this in IFERROR
=VLOOKUP(D2,A2:$B$7,2,0)
I'm trying to do some bootstrapping with a data set in Excel with the formula =INDEX($H$2:$H$5057,RANDBETWEEN(2,5057)), where my original data set in is column H. It seems to work most of the time, but there is always approximately one cell that outputs a reference error. Does anyone know why this happens, or how to avoid including that one cell? I'm trying to generate a histogram from this data, and FREQUENCY does not play nice with an array with an error in it.
Please try:
=INDEX($H$2:$H$5057,RANDBETWEEN(1,5056))
=RANDBETWEEN(2,5057) returns a reasonably arbitrary value of 2 or any integer up to and including 5057. Used as above this specifies the position in the chosen array (H2:H5057) - that only has 5056 elements, so one problem would be when RANDBETWEEN hits on 5057. Much easier to observe with just H2:H4 and RANDBETWEEN(2,4).
Situation: A column containing an number is imported into SSIS as a string. We are converting the string to either an integer or decimal number based on what the data type is expected to be using the Data Conversion task. The Configure Error Output is used redirect both errors and truncation to a script task.
Problem: The SSIS Data Conversion Transformation rounds number values to fit the new data type and does not throw a conversion or truncation error. The row redirect is not happening for numbers. For example, when DT_DECIMAL (10,2) is required, but a value of 12.123 is converted, the value is rounded to 12.12 with no error or truncation redirect. I used a data viewer to verify the Data Conversion task is causing the rounding. Errors from non-numeric characters do cause the row to redirect.
Desired Output: We want to have an error thrown signaling if the data does not match the required data type, for example DT_DECIMAL (10,2).
Is there any way to not have numbers round with the data conversion task, or would another task be required to do this?
You will likely need another task, the Script Component for Data Transformation provides the most flexibility.
You will be able to customize the data conversion and error output in the code.
If you open up the Data Conversion Transformation Editor there's a button to Configure Error Output. From there, you can set the behavior for Truncation to behave in whatever manner you'd like.