필터 지우기
필터 지우기

How to compare one column of one matrix with all columms of other matrix one by one? matlab 2014b

조회 수: 1 (최근 30일)
suppose N is 7x8 matrix, M is 7x8 matrix. both are different i want N(:,1)-M(:,1);N(:,1)-M(:,2);N(:,1)-M(:,3)...........N(:,2)-M(:,1);N(:,2)-M(:,2) and so on. how to do that? please help me. I am using matlab version 2014b.

채택된 답변

Guillaume
Guillaume 2017년 3월 27일
편집: Guillaume 2017년 3월 27일
R2016b or later:
N - permute(M, [1 3 2])
Pre-R2016b:
bsxfun(@minus, N, permute(M, [1 3 2]))
will give you a 7x8x8 matrix where each (:, i, j) is N(:, i) - M(:, j)

추가 답변 (1개)

Jan
Jan 2017년 3월 27일
편집: Jan 2017년 3월 27일
% With Matlab >= 2016b:
sM = size(M);
R = N - reshape(M, [sM(1), 1, sM(2)]);
% With Matlab < 2016b
R = bsxfun(@minus, N, reshape(M, [sM(1), 1, sM(2)]));
  댓글 수: 1
Pooja Patel
Pooja Patel 2017년 3월 27일
편집: Pooja Patel 2017년 3월 27일
I am using matlab 2014b. i have used sM = size(M);R = bsxfun(@minus, N, reshape(M, [sM(1), 1, sM(2)]));. but It is showing error in reshape "To RESHAPE the number of elements must not change."

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by