필터 지우기
필터 지우기

how to add some value to random matrix with specific condition?

조회 수: 2 (최근 30일)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 29일
댓글: Stephen23 2016년 4월 29일
if i have A represent the number of group ones in matrix in the row
A = [ 1 2 0
2 1 1
3 1 1 ]
i want to generate matrix like this depend on A which between the group of ones at least one zero
F = [1 0 1 1 0 0 0
1 1 0 1 0 1 0
1 1 1 0 1 0 1 ]

답변 (1개)

Stephen23
Stephen23 2016년 4월 29일
A = [ 1 2 0
2 1 1
3 1 1 ]
%
N = max(sum(1+A,2));
C = arrayfun(@(n){[ones(1,n),0]},A);
C = cellfun(@(c){[c{:}]},num2cell(C,2));
C = cellfun(@(v){[v,zeros(1,N-numel(v))]},C);
F = vertcat(C{:});
F(:,end) = []
prints the output in the command window:
F =
1 0 1 1 0 0 0
1 1 0 1 0 1 0
1 1 1 0 1 0 1
  댓글 수: 4
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016년 4월 29일
i want to write another question and i will explain what i need clearly
Guillaume
Guillaume 2016년 4월 29일
If you start another question, then you still should accept Stephen's answer considering he did answer the current question correctly.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by