필터 지우기
필터 지우기

how to call the vector from the work space

조회 수: 5 (최근 30일)
Sun Heat
Sun Heat 2019년 8월 25일
댓글: Sun Heat 2019년 8월 26일
suppose, data = [15 2 7 16 16]; and there are 16 different files in the workspace how to call it according to the 'data' vector in bunch of five(as sequence shown in data vector)
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 8월 25일
"and there are 16 different files in the workspace"
Please expand on that. Files can be on disk, but only variables can be in a workspace.
Sun Heat
Sun Heat 2019년 8월 25일
files is on the workspace named M1,M2,M3,M4.......upto...M16.....i have to call it according to 'data' vector.

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 25일
MS = {M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15, M16};
MS(data)
The result will be a 1 x 5 cell array that you would typically use {} indexing to access the contents of.
This code does not assume that the M variables are the same size or are the same data type.
In the case that the M variables are the same size and are a numeric data type, then there are other possibilities, such as
nd = ndims(M1);
MS = cat(nd+1, M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15, M16);
idx = [repmat({':'}, 1, nd), {data}];
MS(idx{:})
This would in this special case give you a numeric array that is one dimension higher than your original arrays, with the extra dimension corresponding to the entries in data. For example if your M variables are all 1024 x 768 x 3 RGB images, then MS would be 1024 x 768 x 3 x 16 and the indexed version would be 1024 x 768 x 3 x 5
  댓글 수: 1
Sun Heat
Sun Heat 2019년 8월 26일
thanks a lot....it's really helps....god bless you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by