🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

How to format csv to contain displacements for several time increments?

User: "Jyge"
Altair Community Member
Updated by Jyge

I want to read in displacement data from a csv-file and then write it as h3d. 

The data will be for several time increments and each time increment contains node id, x-displacement, y-displacement and z-displacement.

I think, tutorial Compose-3010 gives me some ideas, but I am not sure how to put it in praxis.

An elegant way seems to be using fscanf, so if my file had the datalines in a regular format %i,%f,%f,%f (meaning node id as integer and the in a comma separated way, x-, y- and z-displacements as floats), but the problem is those time increments. I am entirely free to format the csv-file in anywhich way I want.

based on the tutorial I could try folllowing

clc; clear all; close all;  fid = fopen('E:\work\Compose\read_results\csvsimple.csv','rt'); A = fscanf(fid,'%d,%f,%f,%f',[4 inf]); fclose(fid); disp(A')

now for a simple data set of 4 nodes:

1,0,0,0 2,0,0,0 3,0,0,0 4,0,0,0

I get what I want, but if I want to provide the data for multiple time increments I have no idea how to do the separation. Essentially I would have something like:

time,0.0 1,0,0,0 2,0,0,0 3,0,0,0 4,0,0,0 time,0.1 1,1.,0,0 2,1.,0,0 3,1.,0,0 4,1.,0,0

now I get empty matrix. I could put the "time" in an additional column, before the node id, but I think it is wasteful and I think not very practical. In the end I might have something like 200000 nodes and maybe 100 time increments. As far as I can see scanf would suck in the whole data and I think it would be too much. So in the end it would be better to do some sequential reading here. Search for some sort of time information and then read the datalines until next increment. At that moment I would also write the data to a h3dfile.

I would appreciate some insight how to do a lean code here, unfortunately the tutorials and help do not give enough guidance.

Find more posts tagged with