[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dumping scalar structure to matrix fails if empty rows exist

From: c031917
Subject: dumping scalar structure to matrix fails if empty rows exist
Date: Fri, 16 Oct 2015 08:28:42 -0700 (PDT)


quite new to Octave, I don’t find a solution despite a lot of try and search

I want to write various scalar structures out to CSV Files, resembling
telemetry data with spurious signal drop outs. I can’t influence the data
sent. The code below works as long as all elements are filled.

But if there are columns which do have column headers with empty values
related to them, the assignment of this empty row to the prepared target
matrix deletes the respective row,
what leads to an  “A(I,J,...) = X: dimensions mismatch” error.

Can I somehow prevent Octave from deleting that rows ? Or do I need a sort
of “arrayfun” Fu to catch those [] cases ? I tried to understand that, but
it is beyond my current level.. 

The resulting CSV File should have the respective column header and empty
cells (e.g. ;;) below.


structIn=struct("time",[1 2 3],"up",[],"left",[],"speed",[22 33]);

%Get each field name from the structure
fieldNames = fieldnames(structIn);

%Create a text string with the field names
headerOut=headerOut(1:end-1); %Trim off last `,` and `\t`

%prepare matrix according to size of struct
matOut=zeros(max(size(structIn.(fieldNames{1}))), length(fieldNames));

if isempty(structIn.(fieldNames{1}));
   for i=1:length(fieldNames)

%Write to csv.
dlmwrite(‘outfile.csv’, headerOut, '');
dlmwrite(‘outfile.csv’, matOut, '-append');                            

View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]