How to divide the original matrix into different matrices according to the strings
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Chao Zhang
el 30 de Mayo de 2021
Comentada: Chao Zhang
el 31 de Mayo de 2021
My idea is create the 'M_ROCK' matrix if the rock_index ==2 (i.e. there are multiple rock types in the model). And then input the number of rock types according to the 'M_ROCK'. The following picture is the screenshot of part M_ROCK.
For example, there are two rock types r1 and r2 in 'M_ROCK', the num then will be input 2, and the values in the 'M_ROCK' will be transferred to the corresponding new matrix M_ORE(this might include M_ORE1 and M_ORE2) and M_WASTE, according to the strings 'r1_mill_tonnage' and 'r2_mill_tonnage'. However, when I run the following code, there is an error 'Row index exceeds table dimensions'.
In this case, there are only two types of rocks, there may be three, four, etc. other situations, how to write a code, can summarize these situations. In other words, input the number of rock types, the values will automically transfer into the corresponding M_ORE (ORE1,ORE2,...) and M_WASTE according to the strings 'rn_mill_tonnage'(n=1,2,3,....)
Thanks in advance for your help!
elseif rock_index == 2
%%
M_ROCK = rock;
M_ROCK = array2table(M_ROCK,'VariableNames',G_Value.Properties.VariableNames);
%Enter the number of rock types and then create the corresponding
%ore matrixs,after determining the multiple rock types
num=input('Please enter the number of rock types:');
%6.Extract ore and waste matrix from ROCK matrix(multiple rock types)
%Setup initial ore and waste matrix respectively
M_WASTE = zeros(R1,C1);%waste matrix for multiple rock types
M_ORE = zeros(R1,C1);
for j = 1 : num
STR = cell(1,num);
STR{j} = sprintf('r%d_mill_tonnage',j);
if table2array(M_ROCK(i,STR{j}))>0
M_ORE(i,:) = table2array(M_ROCK(i,:));
for k = 1:num
M_ORE = zeros(R1,C1,num);
end
else
M_WASTE(i,:)=table2array(M_ROCK(i,:));
end
end
3 comentarios
Walter Roberson
el 30 de Mayo de 2021
STR = cell(1,num);
That should not be within the for j loop.
Respuesta aceptada
Sulaymon Eshkabilov
el 31 de Mayo de 2021
Hi,
Here are some corrections made in your code:
..
STR = cell(1,num);
M_ORE = zeros(R1,C1,num);
for j = 1 : num
STR{j} = sprintf('r%d_mill_tonnage',j);
if table2array(M_ROCK(i,STR{j}))>0
M_ORE(j,:) = table2array(M_ROCK(j,:)); % not "i" but "j"
else
M_WASTE(j,:)=table2array(M_ROCK(j,:)); % not "i" but "j"
end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!