I'm having trouble with loading .txt file in Matlab. The main problem is having not equal rows(connections). First, the file has information about each node in graph. One row has information like this:
1|1|EL_1_BaDfG|4,41|5,1|6,99|8,76|9,27|13,88|14,19|15,91|19,4|21,48...
it means:
id|type|name|connected_to, weight|connected_to, weight| and so on..
And the taks is this:
The structure of the graph should have fields that represent the vertices array of structures , each of which represents a single node . Each of these structures has fields id , type, name , edges and possibly some additional fields that are required due to the specific time ( previousVertexId , weightFromStart ) . Edges is a series of structures that represent one branch each of these structures has fields endVertexId , status and eventual some specific fields to search for ( eg . Weight ) . Status field indicates the state of the switch , which can be 1 or 0. In the start, status is 1
I was trying to use fscanf function, but it only reads one whole line as one string. By using strsplit function i managed to separate those strings with delimiter |. How can I do the same for whole file and after that assign value to each edge(id, type,name,..)?
Best regards,
Dejan
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Using my STRUCTVARS tool
http://www.mathworks.com/matlabcentral/fileexchange/26216-structure-fields-to-variables
you can do it as below. The advantage is that you don't have to first save to a temporary .mat file, but beyond that it's not an approach I'd really recommend.
Learn MATLAB here - https://hackr.io/tutorials/learn-matlab