How to modify data in MatLab code to be csv file

I have this following graph.
Currently, it works using this following data in MatLab code
function [] = TestKShortestPath(case_number)
switch case_number
case 1
netCostMatrix = [inf 1 inf 1 ; 1 inf 1 1 ;inf 1 inf inf ;inf inf inf inf ];
source=3;
destination=4;
k = 5;
otherwise
error('The only case options available are 1, 2 or 3');
end
fprintf('You selected case #%d, a %dx%d network:\n',case_number,size(netCostMatrix,1),size(netCostMatrix,1));
disp(netCostMatrix);
fprintf('The path request is from source node %d to destination node %d, with K = %d \n',source,destination, k);
[shortestPaths, totalCosts] = kShortestPath(netCostMatrix, source, destination, k);
fprintf('\nResult of Function call: kShortestPath(netCostMatrix, source, destination, k) = \n\n');
if isempty(shortestPaths)
fprintf('No path available between these nodes\n\n');
else
for i = 1: length(shortestPaths)
fprintf('Path # %d:\n',i);
disp(shortestPaths{i})
fprintf('Cost of path %d is %5.2f\n\n',i,totalCosts(i));
end
end
end
My problem is, I want to change the data to be input file (.csv), to do so how to modify the above code (especially line 4-7)? Here I have my data file (attached, exampleGraph.csv, that is the same like the above data, case 1). thank you very much

답변 (0개)

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

질문:

2020년 6월 5일

편집:

2020년 6월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by