Borrar filtros
Borrar filtros

question regarding reading .dat file in matlab

1 visualización (últimos 30 días)
jana
jana el 30 de Abr. de 2014
Respondida: Sara el 30 de Abr. de 2014
Hi,
I've a dat file that looks like this:
17 9 0.010426
18 6 0.024578
19 8 0.018038
19 17 0.032405
I was wondering how I could read it in matlab. I have written the following code, but it doesnt give me the right answer. Is there a different way to read .dat file in matlab. I am new to matlab so please help.
function [costs] = adjacencyMatrix(filename)
filename = 'alnet3.dat';
delimiterIn = ' ';
startRow = 1;
startCol = 1;
M = dlmread(filename,delimiterIn,startRow,startCol);
N = M(1,1);
node1 = M(3:end,1);
node2 = M(3:end,2);
cost = M(3:end,3);
pairs = sparse( node1, node2, cost ,N, N ) ;
pairs = pairs + pairs.';
costs = full(pairs);
end

Respuesta aceptada

Sara
Sara el 30 de Abr. de 2014
If the file is like the one you have posted, you can use the load command

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by