Getting multiple outputs on a single variable in MATLAB function block inside simulink.

8 ビュー (過去 30 日間)
Albin Grip
Albin Grip 2021 年 6 月 29 日
コメント済み: Albin Grip 2021 年 6 月 30 日
I'm trying to create a simple MATLAB function block that takes an input 2D matrix (image), and extracts all the rows from this image, outputting them one-by-one into the rest of the simulink model for row-based processing (model to go through HDL coder for FPGA implementation at the end). The problem is that when this is being run inside of simulink, only the last row is being outputted to the rest of the pipeline. How can I fix this function such that it outputs the first row for a bit, then the second row for a bit and so on. I've tried delay blocks in Simulink but I think the modification needs to be done within this MATLAB function block .This is what I have currently:
function row_out = row_extractor(img_dat, start, nrows, ncols)
persistent row_inter;
if isempty(row_inter)
row_inter = uint32(zeros(1, ncols));
persistent row_dat;
if isempty(row_dat)
row_dat = uint32(zeros(1, ncols));
row_out = uint32(zeros(1, 3));
if start == true
for row_index = 1 : nrows
for pixel_index = 1 : ncols
row_dat(pixel_index) = img_dat(row_index, pixel_index);
row_out(pixel_index) = row_dat(pixel_index);

回答 (1 件)

Kiran Kintali
Kiran Kintali 2021 年 6 月 30 日
Use this example to see how to extract a port of the image to stream into DUT suitable for HDL Code Generation.
  1 件のコメント
Albin Grip
Albin Grip 2021 年 6 月 30 日
Hi Kiran, thanks for your reply.
My question is more so related to how to get the different function blocks to run a different number of times within one cycle. So basically theres a 2d matrix (image input) that I want to extract row-by-row (one function call), and for each of those rows theres a processing MATLAB function (so that needs to be called for nrows times), hence a 1:nrows ratio. And after this the cycle repeats with a new image and so forth.
Where as in the example you sent its more so that the each function block (capture column data, median filter and update image) gets called once every clock cycle 1:1:1 ratio to process each pixel individually in the frame.


Community Treasure Hunt

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

Start Hunting!

Translated by