Minizinc - solve minimize does not minimize properly - minizinc

My minizinc program does not minimize properly. It seems to maximize.
The program tries to find the minimum sum of times in which a given number of couriers ( in .dzn),
deliver the packages.
This is
.dzn
n = 5;
c = 2;
times = [| 0, 4, 2, 7, 9
| 4, 0, 4, 8, 9
| 2, 4, 0, 1, 6
| 7, 8, 1, 0, 2
| 9, 9, 6, 2, 0|];
place_names = ["H","A","B","C","D"];
This is
.mzn
include "globals.mzn";
int: n; % total number of places
int: c; % total number of couriers
set of int: num_deliveries = 1..n-1;
int: headquarter = 1;
set of int: num_places = 1..n;
set of int: deliveries = 2..n;
set of int: couriers = 1..c;
set of int: num_max_deliveries = 1..n+2;
set of int: schedule_domain = 0..n;
int: first_place_idx = 1;
int: last_place_idx = n+2;
array[num_places, num_places] of int: times; % estimate of the times needed to reach a place_b from place_a
array[num_places] of string: place_names; % names of places
array[couriers,num_max_deliveries] of var schedule_domain: schedule; % scheduling deliveries with 0 padding
constraint forall(i in couriers)(schedule[i,first_place_idx] == headquarter /\ schedule[i,last_place_idx] == headquarter)
/\ forall(a in couriers, b in num_max_deliveries where b != first_place_idx /\ b != last_place_idx)(schedule[a,b] !=1)
/\ forall(i in couriers)(sum(j in num_max_deliveries)(schedule[i,j]) > 2)
/\ forall(z in deliveries)(count([deopt(el)| el in [ k | k in [schedule[i,j]|i in couriers, j in num_max_deliveries where j != first_place_idx /\ j!= last_place_idx] where k != 0]],z,1))
/\ sum([ k | k in [schedule[i,j]|i in couriers, j in num_max_deliveries where j != first_place_idx /\ j!= last_place_idx] where k != 0]) == sum(2..n);
array[couriers] of var int : total_times = [ sum([times[[schedule[i,j] |j in num_max_deliveries where schedule[i,j] != 0][z], [schedule[i,j] |j in num_max_deliveries where schedule[i,j] != 0][z+1]]
| z in 1..length([schedule[i,j] |j in num_max_deliveries where schedule[i,j] != 0]) -1]) | i in couriers];
var int : sum_time = sum(total_times);
solve minimize sum_time;
output ["schedule = \(schedule)\n"];
output ["total_times = \(total_times)\n"];
output[ "courier_" ++ "\(i) " ++ "\([ place_names[fix(schedule[i,j])] ++ "->" | j in num_max_deliveries where schedule[i,j] != 0])\n" | i in couriers];
This is the output
output
schedule = [1, 5, 4, 3, 0, 0, 1, 1, 2, 0, 0, 0, 0, 1]
total_times = [14, 8]
courier_1 ["H->", "D->", "C->", "B->", "H->"]
courier_2 ["H->", "A->", "H->"]
----------
schedule = [1, 3, 5, 4, 0, 0, 1, 1, 2, 0, 0, 0, 0, 1]
total_times = [17, 8]
courier_1 ["H->", "B->", "D->", "C->", "H->"]
courier_2 ["H->", "A->", "H->"]
----------
schedule = [1, 3, 4, 5, 0, 0, 1, 1, 2, 0, 0, 0, 0, 1]
total_times = [14, 8]
courier_1 ["H->", "B->", "C->", "D->", "H->"]
courier_2 ["H->", "A->", "H->"]
----------
schedule = [1, 0, 5, 4, 3, 0, 1, 1, 2, 0, 0, 0, 0, 1]
total_times = [14, 8]
courier_1 ["H->", "D->", "C->", "B->", "H->"]
courier_2 ["H->", "A->", "H->"]
----------
schedule = [1, 0, 5, 0, 4, 0, 1, 1, 3, 2, 0, 0, 0, 1]
total_times = [18, 10]
courier_1 ["H->", "D->", "C->", "H->"]
courier_2 ["H->", "B->", "A->", "H->"]
----------
schedule = [1, 0, 5, 0, 4, 3, 1, 1, 0, 2, 0, 0, 0, 1]
total_times = [14, 8]
courier_1 ["H->", "D->", "C->", "B->", "H->"]
courier_2 ["H->", "A->", "H->"]
----------
schedule = [1, 0, 4, 0, 5, 0, 1, 1, 3, 0, 2, 0, 0, 1]
total_times = [18, 10]
courier_1 ["H->", "C->", "D->", "H->"]
courier_2 ["H->", "B->", "A->", "H->"]
----------
schedule = [1, 0, 2, 0, 5, 0, 1, 1, 0, 4, 3, 0, 0, 1]
total_times = [22, 10]
courier_1 ["H->", "A->", "D->", "H->"]
courier_2 ["H->", "C->", "B->", "H->"]
----------
schedule = [1, 0, 3, 0, 5, 0, 1, 1, 0, 4, 0, 2, 0, 1]
total_times = [17, 19]
courier_1 ["H->", "B->", "D->", "H->"]
courier_2 ["H->", "C->", "A->", "H->"]
----------
==========
Finished in 422msec
It should stop after the first optimal solution, but it seems that the first solution is the optimal one.
Thanks in advance!

Please, note that the only variable that a solver outputs is schedule. All other are computed using information in own file. I have made an experiment, using JaCoP (I guess similar can be done with Gecode). I compile your problem to flatzinc (option -c), annotated variable sum_time with ":: output_var" and run fan_jacop (you can try fun_gecode) and got the following output.
sum_time = 16;
schedule = array2d(1..2, 1..7, [1, 0, 0, 0, 0, 2, 1, 1, 0, 0, 3, 4, 5, 1]);
sum_time = 14;
schedule = array2d(1..2, 1..7, [1, 0, 0, 0, 0, 2, 1, 1, 0, 0, 4, 5, 3, 1]);
sum_time = 9;
schedule = array2d(1..2, 1..7, [1, 0, 0, 0, 0, 2, 1, 1, 0, 0, 5, 4, 3, 1]);
sum_time = 7;
schedule = array2d(1..2, 1..7, [1, 0, 0, 0, 0, 2, 1, 1, 0, 3, 4, 5, 0, 1]);
sum_time = 5;
schedule = array2d(1..2, 1..7, [1, 0, 0, 0, 2, 0, 1, 1, 0, 0, 5, 4, 3, 1]);
sum_time = 3;
schedule = array2d(1..2, 1..7, [1, 0, 0, 0, 2, 0, 1, 1, 0, 3, 4, 5, 0, 1]);
sum_time = 2;
schedule = array2d(1..2, 1..7, [1, 0, 0, 2, 0, 3, 1, 1, 0, 4, 0, 5, 0, 1]);
sum_time = 1;
schedule = array2d(1..2, 1..7, [1, 0, 0, 3, 4, 0, 1, 1, 0, 2, 0, 5, 0, 1]);
sum_time = 0;
schedule = array2d(1..2, 1..7, [1, 0, 2, 0, 3, 0, 1, 1, 0, 4, 0, 5, 0, 1]);
==========
It indicates that the objective variable is correctly minimized and the problem is in minizinc output program.

Related

Getting the matrix value given a vector of indices along each axis

I have a Matlab matrix M with size: [70 5 3 2 10 9 5 3 21];
I have a vector with a coordinates that I want to read of that matrix: [5, 1, 1, 2, 3, 4, 1, 2, 1];
MWE example of what I am trying to get:
M = rand(70 5 3 2 10 9 5 3 21);
coordinates = [5, 1, 1, 2, 3, 4, 1, 2, 1];
% Output desired:
M(5, 1, 1, 2, 3, 4, 1, 2, 1)
%Current attempt:
M(coordinates)
Clearly M(coordinates) <> M(5, 1, 1, 2, 3, 4, 1, 2, 1). Is there a way of doing this?
It's a bit awkward, but you can convert the array to a cell array, and then to a comma-separated list:
M = rand(70, 5, 3, 2, 10, 9, 5, 3, 21);
coordinates = [5, 1, 1, 2, 3, 4, 1, 2, 1];
coords_cell = num2cell(coordinates);
result = M(coords_cell{:});

google ortools vrp set break fails

I modified the original vrptw.py sample and want to set break for couple vehicles/routes.
from __future__ import print_function
from ortools.constraint_solver import pywrapcp
from ortools.constraint_solver import routing_enums_pb2
def create_data_model():
"""Stores the data for the problem."""
data = {}
data['time_matrix'] = [
[0, 6, 9, 8, 7, 3, 6, 2, 3, 2, 6, 6, 4, 4, 5, 9, 7],
[6, 0, 8, 3, 2, 6, 8, 4, 8, 8, 13, 7, 5, 8, 12, 10, 14],
[9, 8, 0, 11, 10, 6, 3, 9, 5, 8, 4, 15, 14, 13, 9, 18, 9],
[8, 3, 11, 0, 1, 7, 10, 6, 10, 10, 14, 6, 7, 9, 14, 6, 16],
[7, 2, 10, 1, 0, 6, 9, 4, 8, 9, 13, 4, 6, 8, 12, 8, 14],
[3, 6, 6, 7, 6, 0, 2, 3, 2, 2, 7, 9, 7, 7, 6, 12, 8],
[6, 8, 3, 10, 9, 2, 0, 6, 2, 5, 4, 12, 10, 10, 6, 15, 5],
[2, 4, 9, 6, 4, 3, 6, 0, 4, 4, 8, 5, 4, 3, 7, 8, 10],
[3, 8, 5, 10, 8, 2, 2, 4, 0, 3, 4, 9, 8, 7, 3, 13, 6],
[2, 8, 8, 10, 9, 2, 5, 4, 3, 0, 4, 6, 5, 4, 3, 9, 5],
[6, 13, 4, 14, 13, 7, 4, 8, 4, 4, 0, 10, 9, 8, 4, 13, 4],
[6, 7, 15, 6, 4, 9, 12, 5, 9, 6, 10, 0, 1, 3, 7, 3, 10],
[4, 5, 14, 7, 6, 7, 10, 4, 8, 5, 9, 1, 0, 2, 6, 4, 8],
[4, 8, 13, 9, 8, 7, 10, 3, 7, 4, 8, 3, 2, 0, 4, 5, 6],
[5, 12, 9, 14, 12, 6, 6, 7, 3, 3, 4, 7, 6, 4, 0, 9, 2],
[9, 10, 18, 6, 8, 12, 15, 8, 13, 9, 13, 3, 4, 5, 9, 0, 9],
[7, 14, 9, 16, 14, 8, 5, 10, 6, 5, 4, 10, 8, 6, 2, 9, 0],
]
import numpy as np
# data['time_matrix'] = np.full(np.array(data['time_matrixs']).shape, fill_value=1)
# data['time_matrix'] = np.array(data['time_matrixs'])[np.array(data['time_matrixs']) == 0] == 0
data['time_windows'] = [
(0, 10), # depot
(7, 12), # 1
(10, 15), # 2
(16, 18), # 3
(10, 13), # 4
(5, 30), # 5
(5, 10), # 6
(5, 30), # 7
(5, 10), # 8
(5, 10), # 9
(10, 16), # 10
(10, 20), # 11
(5, 30), # 12
(5, 11), # 13
(7, 30), # 14
(10, 19), # 15
(11, 15), # 16
]
data['num_vehicles'] = 4
data['depot'] = 0
return data
def print_solution(data, manager, routing, assignment):
"""Prints assignment on console."""
time_dimension = routing.GetDimensionOrDie('Time')
total_time = 0
print('Breaks:')
intervals = assignment.IntervalVarContainer()
for i in range(intervals.Size()):
brk = intervals.Element(i)
if brk.PerformedValue() == 1:
print('{}: Start({}) Duration({})'.format(
brk.Var().Name(),
brk.StartValue(),
brk.DurationValue()))
else:
print('{}: Unperformed'.format(brk.Var().Name()))
print()
for vehicle_id in range(data['num_vehicles']):
index = routing.Start(vehicle_id)
plan_output = 'Route for vehicle {}:\n'.format(vehicle_id)
while not routing.IsEnd(index):
time_var = time_dimension.CumulVar(index)
slack_var = time_dimension.SlackVar(index)
plan_output += '{0} Time({1},{2}) Slack({3},{4}) -> '.format(
manager.IndexToNode(index), assignment.Min(time_var),
assignment.Max(time_var), assignment.Min(slack_var), assignment.Max(slack_var))
index = assignment.Value(routing.NextVar(index))
time_var = time_dimension.CumulVar(index)
plan_output += '{0} Time({1},{2})\n'.format(manager.IndexToNode(index),
assignment.Min(time_var),
assignment.Max(time_var))
plan_output += 'Time of the route: {}min\n'.format(
assignment.Min(time_var))
print(plan_output)
total_time += assignment.Min(time_var)
print('Total time of all routes: {}min'.format(total_time))
slack_var = time_dimension.SlackVar(int(2))
print(slack_var.Bound())
if slack_var.Bound():
slack_min = assignment.Min(slack_var)
slack_max = assignment.Max(slack_var)
# print("assignment.Min(slack_var): ", assignment.Value(slack_var))
def main():
"""Solve the VRP with time windows."""
data = create_data_model()
manager = pywrapcp.RoutingIndexManager(len(data['time_matrix']), data['num_vehicles'], data['depot'])
routing = pywrapcp.RoutingModel(manager)
def time_callback(from_index, to_index):
"""Returns the travel time between the two nodes."""
# Convert from routing variable Index to time matrix NodeIndex.
if from_index == to_index: return 0
return 1
# from_node = manager.IndexToNode(from_index)
# to_node = manager.IndexToNode(to_index)
# return data['time_matrix'][from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(time_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
time = 'Time'
routing.AddDimension(
transit_callback_index,
30*100, # allow waiting time
50, # maximum time per vehicle
False, # Don't force start cumul to zero.
time)
time_dimension = routing.GetDimensionOrDie(time)
# Add breaks TODO Uncomment
node_visit_transit = {}
for n in range(routing.Size()):
if n >= len(data['time_windows']):
node_visit_transit[n] = 0
else:
node_visit_transit[n] = 0 # int(data['demands'][n] * data['time_per_demand_unit'])
break_intervals = {}
# for v in xrange(data['num_vehicles']):
for v in [0,1]:
# vehicle_break = data['breaks'][v]
break_intervals[v] = [
routing.solver().FixedDurationIntervalVar(
0, 0, 1, False, 'Break for vehicle {}'.format(v))
]
time_dimension.SetBreakIntervalsOfVehicle(
break_intervals[v], v, node_visit_transit)
# Add time window constraints for each location except depot.
for location_idx, time_window in enumerate(data['time_windows']):
if location_idx == 0:
continue
index = manager.NodeToIndex(location_idx)
time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1])
routing.AddToAssignment(time_dimension.SlackVar(index))
# Add time window constraints for each vehicle start node.
for vehicle_id in range(data['num_vehicles']):
index = routing.Start(vehicle_id)
time_dimension.CumulVar(index).SetRange(data['time_windows'][0][0], data['time_windows'][0][1])
routing.AddToAssignment(time_dimension.SlackVar(index))
for i in range(data['num_vehicles']):
routing.AddVariableMinimizedByFinalizer(
time_dimension.CumulVar(routing.Start(i)))
routing.AddVariableMinimizedByFinalizer(
time_dimension.CumulVar(routing.End(i)))
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (
routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
search_parameters.time_limit.seconds = 5
# search_parameters.log_search = True
assignment = routing.SolveWithParameters(search_parameters)
if assignment:
print_solution(data, manager, routing, assignment)
if __name__ == '__main__':
main()
Note:
Transit time is exactly 1
number of vehicles: 4
The break is at the beging
The problem is when I set break (node_visit_transit=1) for more than 2 vehicles, it stucks.
Could you please explain what's wrong with code and why it stuck?
P.S. When I set break for only one vehicle[ex:0 and 1], the output is as following:
Breaks:
Break for vehicle 0: Start(0) Duration(1)
Break for vehicle 1: Start(0) Duration(1)
Route for vehicle 0:
0 Time(1,1) Slack(0,0) -> 0 Time(2,2)
Time of the route: 2min
Route for vehicle 1:
0 Time(1,1) Slack(16,16) -> 0 Time(18,18)
Time of the route: 18min
Route for vehicle 2:
0 Time(0,0) Slack(4,6) -> 13 Time(5,7) Slack(0,2) -> 9 Time(6,8) Slack(0,2) -> 8 Time(7,9) Slack(0,2) -> 6 Time(8,10) Slack(0,2) -> 2 Time(10,11) Slack(0,1) -> 1 Time(11,12) Slack(0,1) -> 4 Time(12,13) Slack(2,3) -> 3 Time(16,16) Slack(0,0) -> 0 Time(17,17)
Time of the route: 17min
Route for vehicle 3:
0 Time(0,0) Slack(10,10) -> 16 Time(11,11) Slack(0,0) -> 15 Time(12,12) Slack(0,0) -> 14 Time(13,13) Slack(0,0) -> 12 Time(14,14) Slack(0,0) -> 11 Time(15,15) Slack(0,0) -> 10 Time(16,16) Slack(0,0) -> 7 Time(17,17) Slack(0,0) -> 5 Time(18,18) Slack(0,0) -> 0 Time(19,19)
Time of the route: 19min
Total time of all routes: 56min
False
Please note, The slack and time for route 2 and 3 of depot is strange

Playing Music in Matlab

I want to access the frequencies one by one from the list of frequencies(Frtm) and want to store them in a signal and at the end i want to play them ...
I have written this code but i don't know where is the problem if anyone one can help then it will be appreciated.
function Music3 ()
Fs = 44100;
T = 1 / Fs;
t = 0:1 / 18:5;
M = zeros (1, 88);
for I = 7:88
M (I) = round (36.8 * (2 ^ (1 / 12)) ^ (I - 6));
endfor
Signal = [];
FrTm = [50, 3; 50, 3; 52, 3; 54, 3; 50, 3; 54, 3; 52, 3; 45, 3; 50, 3; 50, 3; 52, 3; 54, 3; 50, 6; 49, 3; 1, 3; 50, 3; 50, 3; 52, 3; 54, 3; 55, 3; 54, 3; 52, 3; 50, 3; 49, 3; 45, 3; 47, 3; 49, 3; 50, 6; 50, 3; 1, 3; 47, 5; 49, 1; 47, 3; 45, 3; 47, 3; 49, 3; 50, 3; 1, 3; 45, 5; 47, 1; 45, 3; 43, 3; 42, 6; 45, 3; 1, 3; 47, 5; 49, 1; 47, 3; 45, 3; 47, 3; 49, 3; 50, 3; 47, 3; 45, 3; 50, 3; 49, 3; 52, 3; 50, 6; 50, 6];
for i = 1:length (FrTm)
M (i) = FrTm (i);
New = M (i);
data = sin (2 * pi * New / Fs * t);
Signal = [data; Signal];
endfor
stem(Signal);
sound(Signal,44100);
end
Here is what you want:
clear; clc; close all;
Fs = 44100;
T = 1 / Fs;
sin_time_seconds = 1
t = 0:T:sin_time_seconds;
Signal = [];
FrTm = 10*[50, 3; 50, 3; 52, 3; 54, 3; 50, 3; 54, 3; 52, 3; 45, 3; 50, 3; 50, 3; 52, 3; 54, 3; 50, 6; 49, 3; 1, 3; 50, 3; 50, 3; 52, 3; 54, 3; 55, 3; 54, 3; 52, 3; 50, 3; 49, 3; 45, 3; 47, 3; 49, 3; 50, 6; 50, 3; 1, 3; 47, 5; 49, 1; 47, 3; 45, 3; 47, 3; 49, 3; 50, 3; 1, 3; 45, 5; 47, 1; 45, 3; 43, 3; 42, 6; 45, 3; 1, 3; 47, 5; 49, 1; 47, 3; 45, 3; 47, 3; 49, 3; 50, 3; 47, 3; 45, 3; 50, 3; 49, 3; 52, 3; 50, 6; 50, 6];
for i = 1:length (FrTm)
data = sin (2 * pi .* FrTm(i) .* t);
Signal = [Signal data];
end
plot(Signal);
sound(Signal,Fs);
I multiplied the frequencies by 10 else they were too low.
sin_time_seconds is the time you want each sound to be displayed. There were many errors in your script, especially with the dimensions of the vectors you created.

Expanding each element in a (2-by-2) matrix to a (3-by-2) block

I want to expand each element in a (2-by-2) matrix to a (3-by-2) block, using Python 3 --- with professional and elegant codes. Since I don't know the python codes, I will just describe the following in maths
X = # X is an 2-by-2 matrix.
1, 2
3, 4
d = (3,2) # d is the shape that each element in X should be expanded to.
Y = # Y is the result
1, 1, 2, 2
1, 1, 2, 2
1, 1, 2, 2
3, 3, 4, 4
3, 3, 4, 4
3, 3, 4, 4
Not that every element in X is now an 3-by-2 block in Y. The position of the block in Y is the same as the position of the element in X.
Here is the MATLAB code
X = [1,2;3,4];
d = [3,2]
[row, column] = size(X);
a = num2cell(X);
b = cell(row, column);
[b{:}] = deal(ones(d));
Y = cell2mat(cellfun(#times,a,b,'UniformOutput',false));
I appreciate your help. Thanks in advance.
If you are okay with using NumPy module with Python, you can use numpy.kron -
np.kron(X,np.ones((3,2),dtype=int))
Sample run -
In [15]: import numpy as np
In [16]: X = np.arange(4).reshape(2,2)+1 # Create input array
In [17]: X
Out[17]:
array([[1, 2],
[3, 4]])
In [18]: np.kron(X,np.ones((3,2),dtype=int))
Out[18]:
array([[1, 1, 2, 2],
[1, 1, 2, 2],
[1, 1, 2, 2],
[3, 3, 4, 4],
[3, 3, 4, 4],
[3, 3, 4, 4]])
In fact, this is a direct translation of how one would achieved the desired result in MATLAB in an elegant and professional way as well, as shown below -
>> X = [1,2;3 4]
X =
1 2
3 4
>> kron(X,ones(3,2))
ans =
1 1 2 2
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
3 3 4 4
Another way to do it with ndarray.repeat:
>>> X = np.arange(4).reshape(2,2)+1
>>> X.repeat(3, axis=0).repeat(2, axis=1)
array([[1, 1, 2, 2],
[1, 1, 2, 2],
[1, 1, 2, 2],
[3, 3, 4, 4],
[3, 3, 4, 4],
[3, 3, 4, 4]])

find and match multiple values in the same row in array in matlab

I have a data set consists of the following (which are head values for a finite difference groundwater flow model consists of 200 row, 200 column, and 5 layers)
, "id", "k", "i", "j", "f", "Active"
1, 1, 1, 1, 1, 313, 0
2, 2, 1, 1, 2, 315.2.0, 0
3, 3, 1, 1, 3, 301.24, 0
4, 4, 1, 1, 4, 306.05, 0
5, 5, 1, 1, 5, -999.0, 0
6, 6, 1, 1, 6, -999.0, 0
7, 7, 1, 1, 7, 310.57, 0
8, 8, 1, 1, 8, -999.0, 0
9, 9, 1, 1, 9, -999.0, 0
.
.
.
200000, 200000, 5, 200, 200, -999.0, 0
let us assume that I need to find the row that has a specific i,j,k
for example I want to find the row which has i=100, j=50, k=3 to store the value f for multiple i,j,k
I've tried to use find but it finds only the location for a specific item
I know it can be done using for & if but it will be time demanding
Is there a fast way to do so using matlab?
Lets suppose your text file has the following data
"id", "k", "i", "j", "f", "Active"
1, 1, 1, 1, 313, 0
2, 1, 1, 2, 315.2.0, 0
3, 1, 1, 3, 301.24, 0
4, 1, 1, 4, 306.05, 0
5, 1, 1, 5, -999.0, 0
6, 1, 1, 6, -999.0, 0
7, 1, 1, 7, 310.57, 0
8, 1, 1, 8, -999.0, 0
9, 1, 1, 9, -999.0, 0
First read the file through
>> fileID = fopen('testfileaccess.txt');
>> C = textscan(fileID,'%s %s %s %s %s %s','Delimiter',',')
You will get 6 cells representing each column
C =
Columns 1 through 5
{10x1 cell} {10x1 cell} {10x1 cell} {10x1 cell} {10x1 cell}
Column 6
{10x1 cell}
>> Matrix= [str2double(C{2}).';str2double(C{3}).';str2double(C{4}).';].'
the above code will result the i j and k in a matrix with each row representing each variable
Matrix =
NaN NaN NaN
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
then if you want to find for example k = 1 , i = 1 and j = 8 you use find()
find(Matrix(:,1) == 1 & Matrix(:,2) == 1 & Matrix(:,3) == 8)
and there you have it
ans =
8
8th row
row = jcount*kcount*(i-1) + kcount*(j-1) + k
In your case:
row = 200*5*(i-1) + 5*(j-1) + k