How i can find the difference between 2 values.
Mostrar comentarios más antiguos
I have 2 tables, with 1 column and 24 rows each.
I want to find the diferrence between each value in every row.
for example
T1=[1.5
2.5
3.5
4.5]
T2=[1.2
2
3
4]
The answer must be
Diff=[ 0.3
0.5
0.5
0.5]
Respuestas (2)
Jon
el 18 de Jul. de 2022
y = T1 - T2
9 comentarios
Note that there is a MATLAB function, called diff, although capitalized your variable named Diff, it would still help avoid confusion to use a different name for this variable.
Also, what you call "tables" are called matrices or arrays in MATLAB. A MATLAB table is for column oriented data and has additional features, like column names, row names etc. It's a little hard initially learning the terminology, but it is helpful to have the correct names for things to keep things clear.
In your comment to @Torsten you say that "i already did this but the answer is different".
I can not run the code you have attached as it requires other data and maybe functions that I don't have.
For any two column vectors, a and b, with an equal number of elements it is certain that the result of
delta = a - b
will be given by
delta = [a(1) - b(1);a(2) -b(2); ... a(i) - b(i); ... a(n) - b(n)];
If that isn't what you are getting then there must be some confusion about what is in your two vectors.
Please save your variables voltage1 and voltage to a .mat file and just attach the .mat file with these two variables using the paperclip.
"You can see that the results are not correct!"
Please show us one specific value that is not correct.
Lets look for example at the third element:
voltage1 = [1.0350;1.0350;0.9917;0.9997;1.0201;1.0154;1.0250;0.9947;1.0029;1.0308;0.9915;1.0052;1.0200;0.9800;1.0140;1.0170;1.0384;1.0500;1.0235;1.0387;1.0500;1.0500;1.0500;0.9790];
voltage = [1.0350;1.0350;0.9335;0.9907;1.0175;1.0112;1.0250;0.9899;0.9869;1.0247;0.9819;0.9941;1.0200;0.9800;1.0140;1.0170;1.0379;1.0500;1.0228;1.0385;1.0500;1.0500;1.0500;1.0169];
difference = voltage1 - voltage;
voltage(3)
voltage1(3)
voltage1(3) - voltage(3)
difference(3)
What value do you expect to get when you subtract 0.9335 from 0.9917 ?
myrto pieridou
el 20 de Jul. de 2022
"for example in 14th, in my laptop when i runned the code in my laptop, the difference was -0.111, But it must be 0, because voltage1 and voltage are the same number."
Then clearly they are not the same number on your laptop. Please save those arrays (exactly before the subtraction operation, not from anywhere else) in one MAT file and upload it here by clicking the paperclip button.
voltage1 = [1.0350;1.0350;0.9917;0.9997;1.0201;1.0154;1.0250;0.9947;1.0029;1.0308;0.9915;1.0052;1.0200;0.9800;1.0140;1.0170;1.0384;1.0500;1.0235;1.0387;1.0500;1.0500;1.0500;0.9790];
voltage = [1.0350;1.0350;0.9335;0.9907;1.0175;1.0112;1.0250;0.9899;0.9869;1.0247;0.9819;0.9941;1.0200;0.9800;1.0140;1.0170;1.0379;1.0500;1.0228;1.0385;1.0500;1.0500;1.0500;1.0169];
difference = voltage1 - voltage;
voltage1(14)
voltage(14)
difference(14)
myrto pieridou
el 20 de Jul. de 2022
myrto pieridou
el 20 de Jul. de 2022
Glad you got this sorted out. If this answered your question please accept the answer. Thanks @Stephen23 for pressing through the details on this and helping the OP understand.
T1=[1.5
2.5
3.5
4.5];
T2=[1.2
2
3
4];
Difference = T1 - T2
1 comentario
Categorías
Más información sobre Power Converters en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
