Replace values in a matrice

Hey guys, thanks in advance,
I have this range(matrix) that has 1 x 5600 values. After that I perform a calculation , and I get a distance_matrix, that has 1 x 400 values.
Range includes the values in distance_matrix
What I want to do, is find in range the indexes where the values of distance_matrix are, and replace them by RMC, but such as, range continues to have 1 x 5600 values.
How can I do that?

 Risposta accettata

dpb
dpb il 17 Lug 2022
Modificato: dpb il 17 Lug 2022
Seems you're going over and over the same plowed ground here...use logical addressing.
isR=isfinite(D);
R(isR)=RMC;
or
isD=ismember(R,D);
R(isD)=RMC;

5 Commenti

Hey dpb,
Im doing this
First_idx=184;
Last_idx=276;
isR=find(distance_matrix);
range(isR)=RMC;
but I get this error
Unable to perform assignment because the left and right sides have a different number of elements.
Can I solve this? Because I just want to replace values that in distance_matrix are not zero(first_idx to last_idx), and this values appear also appear in range matrix. But I want to replace the values in range matrix, that are equal in distance matrix, and replace by RMC
dpb
dpb il 18 Lug 2022
Modificato: dpb il 19 Lug 2022
I presumed you only computed RMC on the finite elements -- if so, then the two will match identically.
Why are you using find instead -- it'll return true on anything that isn't zero which is the same as using the whole array.
Don't you try any of this at the command line and use small(ish) test cases to understand what various functions are doing????
>> x=[nan inf rand(1,3)]
x =
NaN Inf 0.5853 0.2238 0.7513
>> find(x)
ans =
1 2 3 4 5
>> isfinite(x)
ans =
1×5 logical array
0 0 1 1 1
>>
See the difference?
Also NB:
>> x=[nan inf 0 rand(1,3)] % add a zero element, too...
x =
NaN Inf 0 0.6099 0.6177 0.8594
>> find(x)
ans =
1 2 4 5 6
>> isfinite(x)
ans =
1×6 logical array
0 0 1 1 1 1
>>
Now, you won't have a value for the origin using find; it'll be left out, but you'll still pick up the two bad values so still not right members.
I use find, because I want the values that are not zero, the all values
dpb
dpb il 19 Lug 2022
Well, that doesn't match the computed values or you wouldn't have the mismatch in lengths...
The code put a NaN or Inf out of range and 0 at the origin; the calculation of whatever was over the values in range which are the finite elements -- makes no sense otherwise.
Look this is the way I managed to do, is not fully automatized, but It works for waht I want, i just sometimes need to replace the last line of code, Is there a way I could do this in a more automatic way?
isR=find(y_max);
y_cutted=y_max(isR);
[a,b]=intersect(range,y_cutted);
b=b.';
RMC2=RMC(:,184:255);
range(:,(254:325))=RMC2;

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations in Centro assistenza e File Exchange

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by