function distance = get_distance(source,dest)[~,~, raw] = xlsread('Distances.xlsx');row1 = raw{1,1:end};column1 = raw{1:end,1};pos_row = -1;pos_col = -1;for i = 1:length(column1) if strcmpi(source,column1(i)) == 1 pos_row = i; endendfor j = 1:length(row1) if strcmpi(dest,row1(j)) == 1 pos_col = j; endendif (pos_row == -1) || (pos_col == -1) distance = -1;else distance = raw{pos_row,pos_col};end
MATLAB: I don’t know what is wrong with this code? I have to read an excel file and return the distance between two places. And the output is always -1. I’ve attached the file Distances.xlsx
excelindexing
Best Answer