Why does this not work - Simple Matlab?

조회 수: 1 (최근 30일)
Alex
Alex 2011년 6월 23일
The following creates a matrix, then breaks it into lines, so that I can send each line as a vector to a function. I dont know if this is the best way, but it seems to work (Generally) However if any of the values in the matrix (array) are greater than 9, i.e double figures, it causes an error. Why? and what is there to fix it.
Thanks Guys
Alex
clear
array = [1,2,3;4,5,6;7,8,9]
openb=('[');
closeb = (']');
for ii = 1:length(array);
vv = sprintf('%s',num2str(array(ii,:)))
finalstring(ii,:) = strcat(openb,vv, closeb)
% finalnums(ii,:) = str2num(finalstring(ii,:));
% varargin{ii} = finalnums(ii,:);
end

답변 (1개)

Walter Roberson
Walter Roberson 2011년 6월 23일
That is definitely not a recommended way to proceed. Consider
output = arrayfun(@(K) YourFunction(array(K,:)), 1:size(A,1));
  댓글 수: 3
Alex
Alex 2011년 6월 23일
The function I want to use is call allcomb.
It requires the vectors sent to it like
allcomb([1 2], [34],[5 6])
Each of the vectors is a row in my matrix, however I dont always know the size of my originial matrix
Walter Roberson
Walter Roberson 2011년 6월 23일
Your a has rows that are three columns wide, but what gets sent to your function has to be 2 columns wide per vector ?? Is it a single call to allcomb() with as many arguments as can be pulled out in pairs from A, or is it a limit or 3 pairs? If it is a limit of 3 pairs, then does the second call to allcomb "slide" the pairs over, e.g., allcomb([3 4],[5 6],[7 8]) ?
You have 11 values in the array; you cannot divide that up in to pairs without missing one of the values, not unless each one should slide by one, e.g., allcomb([2 3],[4 5],[6 7]) and so on until the end of the list ??

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by