Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MATLAB to Python conversion
#1
Hi - I am new to Python and am converting some MATLAB code over. I have a question about converting MATLAB nested variables (is that the right term for this?) with varying sizes and dimensions into Python. Is there a way in Python to set up my variable below, filedata(x).shiftinfo.numapples(y,z), equivalently in Python? I'm not sure how to ask without an example. My stripped-down MATLAB example code is below.

files = ['C:\temp\day1.dat','C:\temp\day2.dat'];   % Files to read (1 file for each day apple pickers worked)
for x = 1:numel(files)                             % Loop over each file
   [fid,msg] = fopen(files(x),'r','b');            % Open for reading binary data
   numShifts(x) = fread(fid,1,'uint32');           % Read # of worker shifts on that day
   for y = 1:numShifts(x)                          % Now loop over the shifts
      filedata(x).numFarmers(y) = fread(fid,1,'uint32');  % Read number of farmers working that shift
      for z = 1:filedata(x).numFarmers(y)          % Now read number of apples picked by each farmer on that shift.
         filedata(x).shiftinfo.numapples(y,z) = fread(fid,1,'uint32'); 
      end
   end
end
Right now I'm just storing one set of z values at a time and bookkeeping x,y indices for that entry. Is there a better way?
Reply


Messages In This Thread
MATLAB to Python conversion - by stokd - Jan-18-2020, 02:24 AM
RE: MATLAB to Python conversion - by stokd - Jan-18-2020, 03:34 AM
RE: MATLAB to Python conversion - by perfringo - Jan-18-2020, 06:37 AM
RE: MATLAB to Python conversion - by buran - Jan-18-2020, 07:05 AM
RE: MATLAB to Python conversion - by ibreeden - Jan-18-2020, 11:11 AM
RE: MATLAB to Python conversion - by stokd - Jan-18-2020, 06:14 PM
RE: MATLAB to Python conversion - by stokd - Jan-18-2020, 08:04 PM
RE: MATLAB to Python conversion - by buran - Jan-18-2020, 08:28 PM
RE: MATLAB to Python conversion - by stokd - Jan-18-2020, 08:32 PM
RE: MATLAB to Python conversion - by ibreeden - Jan-19-2020, 10:00 AM
RE: MATLAB to Python conversion - by stokd - Jan-19-2020, 09:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I need to add data types to cython conversion python to c Good_AI_User 1 1,020 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
Photo Matlab to Python Sateesh 0 1,690 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  From Matlab to Python erbab 1 2,030 Oct-27-2020, 02:16 PM
Last Post: jefsummers
  Arrays in MATLAB and PYTHON cokhuatlanyeuthuongconhetmuc 2 2,211 Jul-24-2020, 10:47 AM
Last Post: cokhuatlanyeuthuongconhetmuc
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 2 6,522 Jul-09-2020, 04:46 PM
Last Post: srikanth7482
  Matlab to Python -- Parallel Computing zistambo 1 1,980 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  C to Python code conversion print problem anakk1n 1 2,198 May-22-2020, 04:15 PM
Last Post: deanhystad
  Python uppercase conversion conditions Jaypeng 7 3,007 Apr-29-2020, 11:24 AM
Last Post: jefsummers
  Python v MatLab for graphs and plots CynthiaMoore 4 3,075 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 3,894 Apr-02-2020, 10:29 PM
Last Post: chai0404

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020