How to divide the original matrix into different matrices according to the strings

조회 수: 1 (최근 30일)
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
Chao Zhang
Chao Zhang 2021년 5월 30일
Thanks! But can my idea be realized with matlab?

댓글을 달려면 로그인하십시오.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 31일
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
  댓글 수: 1
Chao Zhang
Chao Zhang 2021년 5월 31일
Thanks for your answer! But this line ' if table2array(M_ROCK(i,STR{j}))>0' has an error Row index exceeds table dimensions

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by