フィルターのクリア

function to calculate summation in matrix

2 ビュー (過去 30 日間)
Firas Al-Kharabsheh
Firas Al-Kharabsheh 2016 年 3 月 31 日
if i have a (M x N) matrix_A with zeros and another (M x N/2) matrix_B filled by number and combine these matrices to each other which the number in the matrix_B represent numbers of 1 in the matrix_A .. For Example
matrix_A = [0 0 0 0 0 0 0 0 0 0 ] ...... 10 of zeros
matrix_B = [1 2 2 2]
the solution must be in a first matrix after apply the function .. for the previous example the solution is
matrix_A = [1 0 1 1 0 1 1 0 1 1]
Note : in matrix_B between each of number of one's there must be a zero or more .
the equation is if N == ∑k(i) + (n-1) then the function will be apply . where ∑k(i) = 1+2+2+2 = 7 , (n-1) is the number of numbers in the row in matrix_B (4 -1) = 3 .. then when we apply the equation .. 10 == 7+3 ------ true then apply the function.
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 31 日
What is your question? to make it clear, post a short example, you don't need to post tens of numbers, just a small matrix, with expected result, explaining how to obtain it, sometimes, the expected result is enough to explain what you want.

サインインしてコメントする。

回答 (1 件)

Roger Stafford
Roger Stafford 2016 年 4 月 1 日
Instead of inserting ones into a pre-existing A of zeros, it is easier to generate A from scratch:
A = [];
for k = 1:size(B,2)
A = [A,ones(1,B(k)),0];
end
A = A(1:end-1); % Remove the extra zero

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by