Corresponding vector values to array values

I have an array 51 by 51 and I have 6 vectors where the vector elements are the dimensions of the array. How i correspoding the vector values to the array values?
I attach an excel file with the array and the vectors.

댓글 수: 4

For your input vector
1 31 11 40 34 46 19 25 24 0 0
what would you expect the result to be? Matrix(31,11), Matrix(40,34), Matrix(46,19), and Matrix(25,24) ?
the result o matrix(1-31),(31-11),(11-40) etc.
I tried with it ,to no avail
[row,col]=size(route);
cost=0;
total=0;
for i=1:row
for j=1:col
A=route(i,j);
B=route(i,j);
cost=array(A,B);
A=B;
B=B+1;
total=total+cost;
end
end
Your matrix is 51 x 51, so it is not immediately clear what matrix(1-31),(31-11) might mean. Are you looking for matrix(1,31) then matrix(31,11) then matrix(11,40) and so on? So a path through the matrix?
for example. when it reads the numbers 1-47 of vector, it will go to the array in row 1 and column 47 and read the number.

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 1월 23일

1 개 추천

Vector = [1 31 11 40 34 46 19 25 24 0 0];
nodes = Vector(Vector ~= 0);
total = sum(Matrix(sub2ind(size(Matrix), nodes(1:end-1), nodes(2:end))));

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2020년 1월 23일

댓글:

2020년 1월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by