フィルターのクリア

saving a matrix

2 ビュー (過去 30 日間)
Kamuran
Kamuran 2011 年 2 月 14 日
Hi,
I am trying to compare my two codes , which should give same results. Both code have the same variable names such as vx vz. I am trying to calculate velecotiy profiles. For that I open to Matlabs and run both codes . Than I write
vz1=vz; save ( ' FT','vza')
and I load FT in the other matlab window, but it directly takes vz values in the the program. And I get 0 as difference, where I should be getting something around 1e-15 ( I know that because I copy paste the results from one to other).
Is there a way to solve my problem witouth changing the variable names?
  2 件のコメント
Paulo Silva
Paulo Silva 2011 年 2 月 14 日
Your question isn't very clear and you didn't provided the needed code.
Kamuran
Kamuran 2011 年 2 月 15 日
Let me try to explain, because I can not provide my all code (it is too long) . I have two different codes , one is evolved from the other, therefore, they have the same variable names, only difference is the way I present my equations.
I am calculating a velocity profile in a cavity such as vz. And I want to compare two results, for that I open two matlabs at the same time and run the codes. Then, in one Command window I write
FT=vz; % vz is (200*200) matrix
save FT
After that I load FT in the second command window;
Load FT
max(max(abs(vz-FT))) % this should be around 1e-15 but matlab gives me 0 . As Matt point out Matlab is overwritting all the variables in the second command window when I load it.

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

採用された回答

Matt Fig
Matt Fig 2011 年 2 月 14 日
When you load, use the functional form of LOAD in order to avoid overwriting your variables.
X = load('FT');
% Then use X.vz, etc.
.
.
.
.
.
EDIT
As I state below in the comment, copy paste is not reliable with floating points. I want to say it again here so the formatting is better.
format long
pi % copy this and paste below
pi- 3.14159265358979
ans =
3.10862446895044e-015
  2 件のコメント
Kamuran
Kamuran 2011 年 2 月 15 日
It is not working.
I wrote
vza=vz; % just to change name hoping that it will work.
FT=vza;
save FT
and in the other window
X=load ('FT')
max(max(abs(vz-X.vza)))
result is 0
Matt Fig
Matt Fig 2011 年 2 月 15 日
If you did what I showed above and got zero difference, I have to question the method you used to find a real difference. Copy and paste with floating point numbers is often unreliable. Try this:
format long
pi % Now copy this using ctrl+c
pi- 3.14159265358979
ans =
3.10862446895044e-015

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

その他の回答 (2 件)

Robert Cumming
Robert Cumming 2011 年 2 月 15 日
The error could be coming from the copy/paste between the two matlabs.
Are you 100% sure that you have different values?
When I do the same as your doing I get a max of 0 (as you do), and if I copy the data from the editor from 1 matlab to another I get an difference of ~1e-15.
But I know my numbers are exactly the same, so the difference is definately coming from the copy and paste step.

Kamuran
Kamuran 2011 年 2 月 16 日
Yes you are right, the difference is coming from copy paste .
Thank you

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by