필터 지우기
필터 지우기

How can you convert an array into multiple inputs?

조회 수: 4 (최근 30일)
Daniel
Daniel 2014년 12월 10일
답변: Azzi Abdelmalek 2014년 12월 10일
I've been wondering about this for some time. Suppose I have a 2 x 4 array of integers, where each column should be a separate input for a function. I know the exact # of outputs of the output array (16 x 4 for this case) Is there a way to force a function to treat them as separate inputs without modifying the function line directly?
If this is possible, is it also possible to do the same for outputs?
The function I'm using is ngrid.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 10일
Can you explain with a short example?
Daniel
Daniel 2014년 12월 10일
편집: Daniel 2014년 12월 10일
I have this matrix
inputs = [-1 1; -2 2; -3 3; -4 4]; inputs = inputs';
& then
[x y z t] = ndgrid(inputs(:,1), inputs(:,2), inputs(:,3), inputs(:,4))
Is the correct solution.
What I'd like to do is generalize it, so that I can build an array of inputs (each input being a row) where
outputs = ngrid(inputs)
Is also produces the correct solution.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 10일
A= [-1 1; -2 2; -3 3; -4 4]'
b=cell(1,size(A,2))
c=num2cell(A,1)
[b{:}]=ndgrid(c{:})

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by