Truncated arrays when using different Version of MATLAB

5 views (last 30 days)
I do most of the programming in my work group but others also have MATLAB installed on their computers. I am currently running R2014b ( I know its old...) My supervisor is running R2016a. I wrote a program that imports various number of data files (excel files) and appends then into a large array then writes the large array back into a new excel file to be used by another program. When the user runs the program they are asked how many files they want to append and since the files are all the same size I can define the size of the final array after the user answers the question but before I start to ingest data. Our work group used a shared drive system so if I run the program or my supervisor does we are both using the exact same MATLAB program and the exact same data files.
The number of rows of data can vary but the number of columns is consistent. One example would be 9 files so the final array ends up being 12962 rows x 31 columns. When I run the program it all works fine. But when my supervisor runs the program sometimes the last two columns of data do not get exported to the EXCEL output file. Sometimes it is just the last column is missing. I have checked and we are both have similar computers with 8 Gb of RAM. We have never been able to get her computer to be able to correctly import and export all the data.
Any ideas?

Answers (1)

Mark
Mark on 7 Jul 2016
%% Constants
monthend = [31 28 31 30 31 30 31 31 30 31 30 31];
%% Find files disp(' '); disp('***Enter the number of days of data to "merge", the month and day numbers***'); disp(' '); NoDays = input('Enter the number of days: ', 's'); Month = input('Enter the month number (e.g., 06: ', 's'); Day = input('Enter the beginning day number: (e.g., 02) ', 's'); Site = input('Enter the Site number: ', 's');
% Create array will all data based on number of days that will read in NoDaysnum = str2num(NoDays); norowforalldays = 1440 * NoDaysnum; alldata = zeros(norowforalldays,31); currentrow = 0;
% Create correct day number daynum = str2num(Day); daychar = sprintf('%02d',daynum);
% Create correct month number monthnum = str2num(Month); monthchar = sprintf('%02d',monthnum);
Filename_Out = strcat('S',Site,'_Radiation_2016_Start_',Month,'-',Day,'.xls');
for k = 1:NoDaysnum
TempName_In = strcat('S',Site,'_Radiation_2016_',monthchar,'_',daychar,'.txt');
fileID_in = fopen(TempName_In,'r');
RadData = csvread(TempName_In,0,1);
datasize = size(RadData);
dates = textscan(fileID_in,'%c %19c %*[^\n]');
% the 693960 accounts for the time different between MATLAB and EXCEL
% time zero.
realdates = datenum(dates{1,2}) - 693960;
realdatestring = datestr(realdates);
fclose(fileID_in);
daynum = daynum + 1;
% Check for day of month to flip to new month
yeardate = year(realdates(1));
fixmonthend = mod(yeardate,4);
if (fixmonthend>0)
monthend(2) = 29;
end
if (daynum > monthend(monthnum))
monthnum = monthnum + 1;
monthchar = sprintf('%02d',monthnum);
daynum = 1;
end
daychar = sprintf('%02d',daynum);
% Combine two arrays into one for i = 1:datasize(1) alldata(currentrow+i,1) = realdates(i); for j = 1:datasize(2) alldata(currentrow+i,j+1) = RadData(i,j); end end currentrow = currentrow + datasize(1); end
% Remove extra column caused by either the csvread function or stray blank % at the end of data record. datasize = size(alldata); alldata(:,datasize(2)) = [];
% Output data
xlswrite(Filename_Out,colnames,'Sheet1','A1'); % enter column names in row 1 xlswrite(Filename_Out,alldata,'Sheet1','A3'); % start data entry in row 3

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!