Multi-dimensional arrays indexing for an embedded matlab function in simulink

4 vues (au cours des 30 derniers jours)
Quick Baground: This is an embedded MATLAB function for simulink in which it takes the elements Base Image(An image containing 3 objects), Count(Number of Objects), BBox(Coordinates of Box surrounding each object). Then uses this to create 3 different images in which in each one one of the 3 different objects is blacked out by the Bbox.(NOTE: This algorithim needs to be somewhat versatile so the number of images regardless of the count needs to be stored in one final image) So here is the base code:
function images = fcn(boxes,c,baseimage)
%#codegen
persistent h;
if isempty(h)
h = vision.ShapeInserter('Fill',true,'Opacity',1.0);%Systems object to black out objects
end;
count = c(:,1);
image = baseimage(:,:,1);
dim = size(baseimage);
x = dim(1,1);
y = dim(1,2);
images = zeros(x , y);
for g = 1:count
Pts = rot90(boxes(:,g));%Rotate by 90 to meet input parameters for step function%
images(:,:,g) = step(h, image, Pts);%This is the step I have problem with described below in which the seperate images are blacked out and stored%
end
The Problem: That everytime I run the following code it goes into a debugging mode. No matter what I try I can't find away to take the 3 separate images and index them into one. The issue most likely resides with Simulink because the algorithm runs fine in just MATLAB. The solution doesn't have to be limited to just multi-dimensional arrays but anything that allows me to store my images and import them.
  3 commentaires
David-Linus Hamann
David-Linus Hamann le 27 Juil 2011
I have a fully coded algorithm in MATLAB but I want to make it compatible for real time simulation so that is why I'm trying to do transfer it to Simulink
Fangjun Jiang
Fangjun Jiang le 27 Juil 2011
Simulink simulation is not real-time.

Connectez-vous pour commenter.

Réponse acceptée

Denis Gurchenkov
Denis Gurchenkov le 26 Juil 2011
Please try replacing
> images = zeros(x,y);
with
> images = zeros(x,y,count);
Embedded MATLAB function block does not support growing arrays on assignment. Basically, if you want to have a 3-D array of x-by-y-by-count elements in the end, you have to allocate it as such at the beginning.
Let me know if the above fix does not work for you.
Cheers,
Denis.
  2 commentaires
David-Linus Hamann
David-Linus Hamann le 27 Juil 2011
Sorry for taking a while to respond but I think this might just be an easy port issue but when I applied your fix Simulink gave me an error saying "Expecting Variable Size Matrix " So I just went to the port settings to resolve the signal and I got the error:
Variable 'images' is resolved in workspace ('base') for block 'SucessfullCloudCenterMet/MATLAB Function2/ SFunction ' but it is not a 'Simulink.Signal' object
I'm pretty sure I just might need to convert it or something if You don't know that's fine I'm pretty sure I can work with this Thank You!
Fangjun Jiang
Fangjun Jiang le 27 Juil 2011
That error message indicates something else. Right click the signal labeled as 'images', select 'signal properties', uncheck the option 'signal must resolved to workspace object'.

Connectez-vous pour commenter.

Plus de réponses (1)

Denis Gurchenkov
Denis Gurchenkov le 27 Juil 2011
Hi David-Linus,
As Fangjun said, these look like two different issues. Can you show me your model so I can see the problem?
  1 commentaire
David-Linus Hamann
David-Linus Hamann le 27 Juil 2011
Thank you for your time your top solution worked to a degree all I needed to do was the change the settings for variable-sized functions from array's to structures with time in the Data Import/Export Pane thank you for your help.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by