I have a matrix X (N,100), i have a function which calculate for each column of X another array h(1,50), a would like to calculate for each column of X(N,:) a vector h and making them all in a matrix H(100,50). Can someone help

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 1월 30일
편집: Andrei Bobrov 2018년 1월 30일

1 개 추천

m = size(X,2);
out = zeros(m,50);
for ii = 1:m
out(ii,:) = your_function(X(:,ii));
end

댓글 수: 4

with this code i get only the last value at the array = m for others it still 0
Jos (10584)
Jos (10584) 2018년 1월 30일
Andrei made a small mistake:
use out(ii,:) = ...
rather than out(m,:) = ...
yes i did it works Thank you
Andrei Bobrov
Andrei Bobrov 2018년 1월 30일
Thank you Jos! I am corrected.

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2018년 1월 30일

0 개 추천

Just to make sure: X has 100 columns, You have a function that takes a column and returns a row-vector of 50 columns. And now you want to do this for each column of X and stack all results in a 100-by-50 array. Something like this will help you:
myfun = @(c) [1:50] * mean(c(:)) ;
% just a function that takes a (column) vector and returns a 1-by-50 vector
C = arrayfun(@(k) myfun(X(:,k)), 1:size(X,2), 'un', 0) ; % apply to each column of X
h = cat(1,C{:}) ; % stack each 1-by-50 cell into an array

카테고리

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

질문:

2018년 1월 30일

댓글:

2018년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by