Simulink element wise multiplication for big data

Hi all,
I'm new to simulink. In matlab i run a function which takes 100000*10 size of data and gives an output of 100000*1 within 2 sec as the function is taking element wise multiplication(.*) instead of running in a for-loop row by row. I want to implement this function in simulink to take the advantage of blocks(to edit the formula easier in later stages). I've created my model but when i try to run the simulation, my laptop freezes(may be because of out of memory). How to perform element wise multiplication instead of time based simulation? Is simulink only for time based simulation? Sample program,
data=rand(100000,10);
map.BP_x=[1,2,3,4,5,6];map.BP_y=[1,2,3,4,5,6];map.data=rand(6,6);
function output=my_fun(data,map)
interpolation_data=interp2(map.BP_x,map.BP_y,map.data);
output=interpolation_data*data(:,1)+data(:,2)+data(:,3)+data(:,4)+data(:,5)+...;
end

5 件のコメント

dpb
dpb 2018 年 10 月 13 日
interpolation_data=interp2(map.BP_x,map.BP_y,map.data);
is bad syntax; the sample values array map.data must be the first argument, not the last.
interpolation_data=interp2(map.data,map.BP_x,map.BP_y);
What is the result of
output=interpolation_data*data(:,1)+data(:,2)+data(:,3)+data(:,4)+data(:,5)+...
supposed to be? You speak of element-wise multiplication in the Q? text but use array multiply in the above. Either way, the dimensions aren't consistent as you have sizes for the operation as
[1x6]*[100000x1] + [100000x1] + [100000x1] + ...
First need to define what it is you're actually trying to calculate.
Vick
Vick 2018 年 10 月 15 日
編集済み: dpb 2018 年 10 月 15 日
Hi dpb, My mistake. Actually my original function is too big to write here so i've created a manual function here for demo, Where i've done mistake on interp2 function. Below is my modified Code,
data=rand(100000,10).*10;
map.BP_x=1:2:11; map.BP_y=1:2:11; map.data=rand(6,6);
function output=my_fun(data,map)
interpolation_data=interp2(map.BP_x,map.BP_y,map.data,data(:,9),data(:,10));
output=interpolation_data*data(:,1)+data(:,2)+data(:,3)+data(:,4)+data(:,5)+data(:,6)+data(:,7)+data(:,8);
end
dpb
dpb 2018 年 10 月 15 日
So now instead you have
[100000x1] * [100000x1] + [100000x1] + [100000x1] + ...
You still have a size issue with the matrix multiply and you've yet to specify what you expect the result to be.
Don't let the size of the array get in the way, it doesn't matter if the array length is 10^9 or just 10, matrix multiply must be conformant in the inner dimensions or use element-wise operator if it is the point-by-point product of elements between the two vectors you are trying to compute.
Only you know what it is you're trying to calculate...
BTW, presuming the last terms in the expression of X(:,2)+X(:,3)+... is correct, write that as
sum(X(:,2:8),2)
instead.
Vick
Vick 2018 年 10 月 15 日
Omg again the mistake Actually that is a dot product, output=interpolation_data.*data(:,1)+data(:,2)+data(:,3)+data(:,4)+data(:,5)+data(:,6)+data(:,7)+data(:,8); end
If you see the output that will be of size 100000*1.
What I excctly want is that if I put the same function model in simulink using sum,lookup table, product blocks, simulink will process the data like for 1 sec. So it is kind of running in a for loop. I need a process that simulink takes a whole row of data at one shot and does .* Which will save processing time.
dpb
dpb 2018 年 10 月 15 日
output=interpolation_data.*data(:,1)+sum(data(:,2:8),2);
I've never even seen a Simulink installation so I've zero knowledge about how it actually operates.
I thought a S-function would operate to compute its result with the current inputs at each timestep evolution???
If that's not so, I have nothing I can add, sorry.

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2018a

質問済み:

2018 年 10 月 13 日

コメント済み:

dpb
2018 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by