From: Bruno Luong on 6 May 2010 16:18 "Sergei Koulayev" <sergei.koulayev(a)mathworks.com> wrote in message <hrv5v5$742$1(a)fred.mathworks.com>... > Steve: I know we are talking different languages here, you are the developer, I'm the user. As a user, I don't mind bumping up from logical to double, or from int8 to double, if that's necessary to give me a result I want. Just imagine that I create a variable X somewhere on the line #12 and it just happened to be stored at Integer. Or Logical. Then later at the line #133 I try to write X(3)=pi. I really want this "pi" to be there! Instead of doing just what I told him to do - just put the number in there - Matlab is *invisibly* correcting my operation, giving me a wrong answer that I didn't expect. Who would be happy about that? I want "what you see is what you get" as a consistent behavior. Oh, but Matlab certainly gives "what you see is what you get", the difficulty for "user" is to see line #133 AND also line #12. If you see *only* line #133 then what you see is not what MATLAB see. After all, you are the one who code the line #12, isn't it? Do you have any valid excuse not seeing it? Bruno
From: Walter Roberson on 6 May 2010 16:22 Sergei Koulayev wrote: > As a user, I don't mind bumping up from logical > to double, or from int8 to double, if that's necessary to give me a > result I want. Just imagine that I create a variable X somewhere on the > line #12 and it just happened to be stored at Integer. Or Logical. Then > later at the line #133 I try to write X(3)=pi. I really want this "pi" > to be there! Instead of doing just what I told him to do - just put the > number in there - Matlab is *invisibly* correcting my operation, giving > me a wrong answer that I didn't expect. Who would be happy about that? I > want "what you see is what you get" as a consistent behavior. I know some languages that can do that with respect to some indexable objects (e.g., Maple lists), but I cannot think of _any_ language that will do that for objects that have been formally declared as arrays. I dunno... LISP might if anything does. What I would suggest to you, Sergei, is to use cell arrays for all of your work instead of numeric arrays. X{3} = pi; *will* change the datatype of X{3} to double. You will largely lose the ability to vectorize numeric computations, but if you want WYSIWYG storage then you are going to lose efficiency anyhow.
From: Sergei Koulayev on 6 May 2010 16:27 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hrv79o$5qa$1(a)fred.mathworks.com>... > "Sergei Koulayev" <sergei.koulayev(a)mathworks.com> wrote in message <hrv5v5$742$1(a)fred.mathworks.com>... > > >Then later at the line #133 I try to write X(3)=pi. I really want this "pi" to be there! > Instead of doing just what I told him to do - just put the number in there - Matlab is *invisibly* correcting my operation, giving me a wrong answer that I didn't expect. > ==================== > > But then why wouldn't you define X (or convert it) to a data type that can hold pi. You say you don't want MATLAB to invisibly alter your choice of data, but you do seem to want it to invisibly alter your choice of data type. Why is one better than the other? This is because my choice of data has first order effect on the correctness of the numerical results. While the choice of data type - these matter only for storage and maybe for efficiency of computations - clearly, secondary matters. Matlab agrees with this point and creates variables as doubles by default. Indeed, why would you store zeros(1,2) as a double? It is not efficient. Expecting users to track data types is not realistic. I guess this logical thing that I encountered is really the only place where problems might happen. But going from philosophy to practice, how
From: us on 6 May 2010 16:38 "Sergei Koulayev" <sergei.koulayev(a)mathworks.com> wrote in message <hrujad$fmn$1(a)fred.mathworks.com>... > People, > > check this out. I always thought I could treat 0-1 resulting from the logical operations as numbers. But apparently not. Why? It is completely unintuitive and dangerous. Can somebody give me a meaning of the following example? > > a = rand(100,1); > i = a<0.5; > i = i.^2; > i(i==0) = 2; > unique(i) > > ans = > > 1 > 2 > > i = a<0.5; > i(i==0) = 2; > unique(i) > > ans = > > 1 two things 1) there was a pre-LOGICAL era when any array ]0,1[ did the job 2) there is, indeed, an inconsistency on how ML treats LOGICALs compared to other classes... atf=false; atf^pi % ans = 0 class(atf) % ans = logical au8=uint8(1); au8^pi %{ ??? Error using ==> power Integers can only be raised to positive integral powers. %} just a thought us
From: Bruno Luong on 6 May 2010 16:40
"Sergei Koulayev" <sergei.koulayev(a)mathworks.com> wrote in message <hrv8mp$9j2$1(a)fred.mathworks.com>... > Expecting users to track data types is not realistic. Of course it is. IMHO the three most important commands absolutely must known by new Matlab users are: DEBUG SIZE CLASS Bruno |