Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
could anyone tell me how to replace the value of the given matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
A=[0.01 0.02 0.03 0 0 0 0.02;
0.02 0.03 0.04 0 0 0 0.03;
0.03 0.02 0.02 0 0 0 0.04]
if i add all the numbers it comes 0.31. Could anyone tell me how to replace the number present not the zeros in such a way that if i add the numbers in the matrix it should be 0.35
4 Commenti
Stephen23
il 29 Gen 2018
Modificato: Stephen23
il 29 Gen 2018
@Rik Wisselink: thank you for the concern. I actually want to help Prabha Kumaresan get a good solution... but it is not clear to me why Prabha Kumaresan is avoiding the use of the one function that easily solves this task. An explanation is what I am after!
Jan
il 29 Gen 2018
Modificato: Jan
il 29 Gen 2018
@Stephen: Prabha does not give us explanations. It seems to be more a problem of the communication than of Matlab. Then this problem cannot be solved by communicating in the forum. We cannot help everybody, but all we can do is to suggest working solutions. We did this as good as we can, so it is time to be satisfied - even if the OP is not.
But driving crazy would be a reasonable reaction also. ;-)
Risposte (2)
Stephen23
il 29 Gen 2018
Modificato: Stephen23
il 29 Gen 2018
>> A = [0.01 0.02 0.03 0 0 0 0.02; 0.02 0.03 0.04 0 0 0 0.03; 0.03 0.02 0.02 0 0 0 0.04];
>> A(A~=0) = randfixedsum(nnz(A),1,0.35,0.01,0.09)
A =
0.010084 0.024919 0.042718 0.000000 0.000000 0.000000 0.011433
0.011970 0.010413 0.011182 0.000000 0.000000 0.000000 0.055572
0.036536 0.016813 0.054944 0.000000 0.000000 0.000000 0.063416
>> sum(A(:))
ans = 0.35000
It is not clear why you are wasting so much of your time avoiding using randfixedsum.
0 Commenti
the cyclist
il 26 Gen 2018
A = 0.35*A/sum(A(:));
8 Commenti
Jan
il 29 Gen 2018
@Prabha: I do not see the problem.
A = [0.01 0.02 0.03 0 0 0 0.02; ...
0.02 0.03 0.04 0 0 0 0.03; ...
0.03 0.02 0.02 0 0 0 0.04]
A = 0.35 * A / sum(A(:));
Now sum(A(:)) is 0.35, exactly what you have asked for.
It is not useful to suggest another tool instead of randfixedsum, if this tool works perfectly.
Walter Roberson
il 29 Gen 2018
The sum comes out as the closest representable floating point number to 35/100 which is the same floating point number that is used for the constant 0.35
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!