Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to write 2d Array from 1dArray in Simulink ?

Subject: How to write 2d Array from 1dArray in Simulink ?

From: Pixel

Date: 26 Sep, 2013 14:07:05

Message: 1 of 3

Hi all,
Here is my code

//1d to 2d array in Simulink
// mxarray is not supported

function ans= 2dArray (u)
%#codegen

coder.extrinsic('fopen');
coder.extrinsic('fprintf');
coder.extrinsic('fclose');

fileW = fopen('F:\ADAs\Simulink\InP.txt','w');
fprintf(fileW,'%f \n',u);
fclose(fileW);

// Reading one D Array from file
coder.extrinsic('textread');
data = textread('F:\ADAs\Simulink\InP.txt', '%f', 'delimiter', '\n');

// data contains 307200 elements ( 1d Array)
MCheck = zeros(480,640);
Index =1;
// Loop for writing 1d array to 2d array
       for iy=1:1:480
          for ix=1:640
           MCheck(iy,ix) = (data(Index));
               Index= Index +1;
          end
       end

Suggestions are welcome.
Thanks in advance
ans =0;

Subject: How to write 2d Array from 1dArray in Simulink ?

From: Phil Goddard

Date: 28 Sep, 2013 17:48:05

Message: 2 of 3


The code appears to write u to a file then immediately read it back in -- why are you wanting to do that?

To answer your specific question, have a look at
>> doc reshape

Phil.

Subject: How to write 2d Array from 1dArray in Simulink ?

From: dpb

Date: 28 Sep, 2013 18:05:19

Message: 3 of 3

On 9/26/2013 9:07 AM, Pixel wrote:
> Hi all,
> Here is my code
>
> //1d to 2d array in Simulink
> // mxarray is not supported
>
> function ans= 2dArray (u)
...
     ans=reshape(u,480,[]);


Of course, you can dispense with the function entirely and simply use
reshape() inline.

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us