フィルターのクリア

could anyone help me to solve the following issue

3 ビュー (過去 30 日間)
jaah navi
jaah navi 2019 年 6 月 3 日
回答済み: Image Analyst 2019 年 6 月 6 日
A=[4.7908 5.0104 5.1329 5.3186 5.3094 5.3070 5.4452 5.5001;
0.0958 0.0994 0 0 0.1848 0.2020 0.1851 0.2146;
0.0848 0 0.1469 0.1859 0.1767 0.1854 0.1856 0.1648;
0 0 0 0 0 0 0 0;
0 0.0896 0.1619 0.1351 0 0 0 0;
0 0 0 0 0 0 0 0]
In row 4 and row 6 all numbers are found to be zero.
Could anyone help me how to rearrange the existing numbers in each column such that each row should contain at least one non zero value and each column should containg three non zero values.
  2 件のコメント
TADA
TADA 2019 年 6 月 3 日
Do you want it to happen randomly?
jaah navi
jaah navi 2019 年 6 月 3 日
yes randomly.

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

採用された回答

Image Analyst
Image Analyst 2019 年 6 月 6 日
Here is one way. Just brute force scramble the array until it meets the criteria:
A=[4.7908 5.0104 5.1329 5.3186 5.3094 5.3070 5.4452 5.5001;
0.0958 0.0994 0 0 0.1848 0.2020 0.1851 0.2146;
0.0848 0 0.1469 0.1859 0.1767 0.1854 0.1856 0.1648;
0 0 0 0 0 0 0 0;
0 0.0896 0.1619 0.1351 0 0 0 0;
0 0 0 0 0 0 0 0];
[rows, columns] = size(A)
tryAgain = true;
maxIterations = 1000000;
loopCounter = 0;
while tryAgain && loopCounter < maxIterations
randomIndexes = randperm(numel(A));
A = reshape(A(randomIndexes), rows, columns);
% Check that each row has at least 1 non-zero value
rowsOK = sum(any(A, 2)) == rows;
% Check that each column has at least 3 non-zero values
columnsOK = all(sum(A ~= 0, 1) >= 3);
loopCounter = loopCounter + 1;
if rowsOK && columnsOK
break
end
end
fprintf('Found this A after %d iterations:\n', loopCounter);
A

その他の回答 (1 件)

PIYUSH AGGARWAL
PIYUSH AGGARWAL 2019 年 6 月 3 日
Hi Jaah,
I just switched the values marked in the figure in MATLAB command line.
I think now your requirement of having atleast one non zero number in each row and atleast three non zero numbers in a column is satisfied.
Hope that this works for you
Feel free to reply to this thread if you have additional questions. Furthermore, if this did not address the question you asked, please let me know what I misunderstood so that I can ivestigate further.​
Capture.JPG
  3 件のコメント
PIYUSH AGGARWAL
PIYUSH AGGARWAL 2019 年 6 月 5 日
I can help you provide the code if you tell me what exactly what you want to do with this data because you said something about randomness in the baove comments. Please explain a little further about the randomess comment there, Are you generating this data using rand functions ? And pls upvote answers (will be a help for us :) )
jaah navi
jaah navi 2019 年 6 月 6 日
What I need exactly is
sum(A~=0,2) and
sum(A~=0,1) should not be equal to zero and it can equal to 1 or more than 1.
Could you please help me on it.

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

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by