1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| path = 'C:\Users\Test3.xlsx'; %Path to the Excel
[~,~,data] = xlsread(path); %Open and read the Excel with Mat lab
prob=unique(data(1:end,2)); %count and shows all the different errors
vehicle=unique(data(1:end,1)); % count and shows all the different vehicles
c=0; %initialization of the variable c
result = prob;% initialization of the first colon of the result array
X = {0}; % creation of a cell containing 0
X = repmat(X,length(result),1); % "reproduce the array (repmat)", transform the cell containing a 0 in a array of cells with the size of the number of problems containing 0
result(:,2) = X;% includes in the array a second colon containing only 0
d={data{i,2}};
e={data{i,1}};
f={vehicle{k}};
g={data{i,3}};
h={vehicle{k,2}};
for k=1:length(vehicle) %initialization of the first 'for' loop with k=1 to k=number of vehicles
for i=1:length(data)% initialization of the first 'for' loop with i=1 to i=number of lines in data
if strcmp(e,f)& strcmp(d,'Funktionale Sicherheit: Fehler Fahrtrichtung') %if the cell on the line i of the first colon (vehicles) = to vehicle stocked in the cell k, AND that the problem corresponding to vehicle = A
c=c+1; %counts the number of loops done (25 in Test3)
vehicle{k,2}=data{i,3}; %Add the kilometers belonging to the problem A to the vehicle line k in the colon 2
continue %if the conditions are fulfilled, goes out of the loop
else
end
end
end
for k=1:length(vehicle)
for i=1:length(data)
if strcmp(e,f) & strcmp(g,h) %if the kilometers stocked in the vehicle array correspond to the one colon 3 of data
for j=1:length(prob)
if data {i,2}==prob{j} %if the problem of colon 2 of data correspond to the problem stocked in prob at the line j
result{j,2}=result{j,2}+1; %Add 1 to the value (0) to count the number of vehicles who have the problem A et prob{j} at the same kilometer
else
end
end
end
end
end
result %Shows the result array |
Partager