Reset Parameter Values to original value read from Excel sheet - anylogic

I have parameters that's read its values from Excel spread sheet (Picture 1). However, I have a method that reduce the parameter values by x% (picture 2). I could reverse the calculation method in picture 2 which not going to help much.
Question:
I want to create a bottom that reset the parameters values to its original excel values. I am not sure how to create such a method? Appreciate any hints or ideas.

First of all, this is very redundant code you code put into a for-loop (select all your params, right click, then create a collection of Doubles).
Then, you can easily loop across all these again and simply divide them by interNo, getting you the original values.

Related

How to copy data from a 1 x 1 double timeseries to a 1 D Lookup Table in Matlab

I have been asked to look at a Matlab project. I'll link sceenshots to clarify the problem. I need to create a 1 D Lookup table with the data from a 1 x 1 double timeseries from another model that has been supplied. One problem is that there are a lot of data points (12500). Is it possible to copy these points across without having to drag the mouse down over the whole 12500 points? Someone has actually tried this dragging the mouse over all the points method and said it didn't work anyway, but I don't really want to try it myself, as it would be way to cumbersome for my liking, even if it did work.
Here is an example of what the 1 x 1 double timeseries looks like (just using 5 points instead of 12500 for simplicity's sake):
Here is the model with the 1D look up table highlighted in blue at the left:
Here is what the 1-D lookup table looks like when opened:
Any insight appreciated.
I've worked out how to copy the data from the timeseries table (actually from the input to this, which is a 1 x 1 struct), but he problem is that the values have no commas between them and the 1-D lookup table requires commas.
Note that the problem has now been solved using Excel, although not by the method I was trying to make work in the question. An answer has been posted which may work, but I'm not sure if i will go to the trouble of attempting to implement it or not at this stage. However, if need be and all being well, I will either do that or delete the question.
You can import a look-up table object (Simulink.LookupTable-object) from both, the MATLAB workspace or directly from Excel.
If you want to automate it, it basically comes down to these two points:
"
Open the model containing the lookup table block and in the Modeling tab, select Model Settings.
In the Model Properties dialog box, in the Callbacks tab, click PostLoadFcn callback in the model callbacks list.
... the next time you open the model, Simulink® invokes the callback and imports the data.
"
After a little thought I feel like the answer is actually fairly trivial: it just can't be done. The input field of the look up table just can't hold 12500 points, most of which have 9 or so decimal places, so there's no way to do this.
This isn't to say there's no way to put the data into the model: this can be done using Excel.

using from workspace block in simulink

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]

Change value inside a loop on Matlab

I have a question about how can I use different values in each iteration with a loop. I have an image with 145 bands. I calculate the size, the number of rows, columns and bands
size=size(HYP);
nrow= size(1);
ncolu= size(2);
nbands= size(3);
I have to do an operation for every band, and then obtain the result but I don't know how to change one of the values automatically for every iteration. I'm going to try to simplify the question. This is my loop. The value rad1 is defined before. I need that on every loop uses some value defined before (for example, band2 value rad2, band3 rad3...) and extract a result for each one (nd1 changes automatically to nd2, etc.)
output= zeros(nrow,ncolu,nbands);
for banda=1:nbands;
nd1= -((3.141592*rad1)/-HYP2(:,:,1));
output(banda,1)= (nd1);
end
end
So, for the first iteration:
nd1= -((3.141592*rad1)/-HYP2(:,:,1));
output(banda,1)= (nd1);
for the second...
nd2= -((3.141592*rad2)/-HYP2(:,:,2));
output(banda,2)= (nd2);
Rad1,rad 2... rad145 etc is defined before. And at the end, output would be a 145 band matrix.
Do you know how can I do it? Really thanks in advance,
Don't try using different variable names. Just use rad(1), rad(2) etc. and then
output= zeros(nrow, ncolu, nbands);
for banda=1:nbands;
output(:,:,banda) = -((3.141592*rad(banda))/-HYP2(:,:,1));
end
(Your initialization of output doesn't match the code in your loop, by the way.)

Matlab: Element by element selection without loops

I have one big matrix of for example 3000X300. And I need to select each element and do several calculations with it. I looked into using the array fun function but because the output of my program is not one value this is not possible.
It works fine now with the loops but it has to preform much faster, so i want to remove the for loop.
Maybe i'll try to be more specific: Each value of the big matrix has to give me an answer of 4 different matrices with the size of 4X6020..
So i don't know if this is possible making this vectorized...
Maybe somebody has other suggestions to make it faster?
greetings,
You can use arrayfun and set uniformoutput to false. See here.

Tanimoto Coefficient using Matlab

I need to calculate Tanimoto Coefficient. I don't know what's wrong in my code. I have 2 nearly similar images. But the value obtained using my code indicates that the two images are highly dissimilar. Kindly help me with my code.
%Tanimoto coeff
I=imread('sliver3.jpg');
J=imread('ref5.jpg');
figure,imshow(I),title('Original');
figure,imshow(J),title('Reference');
inter=intersect(I,J,'rows');
uni=union(I,J,'rows');
si=size(inter);
su=size(uni);
tc=si/su
I attach three images here. First one is the segmented output. Second is a reference image.Third is also a reference but which is highly dissimilar. So, the output must be that, first and second must be nearly similar and first and third must be highly dissimilar. But I'm getting the opposite.
For first two images, tc =0.4895
For first and third images, tc=0.5692
Kindly help me out.
I think you should use the sum() function on union and intersect instead of size() since the Tanimoto Coefficient is the "summation of the intersect"/"summation of the union"