fangq/jsonlab

Encoding scalar values into array unnecessarily

wrgrant opened this issue ยท 1 comments

Last one (for now) ๐Ÿ˜‰

I notice that in this line you are packing scalar values into an array.
But only for floats. Integers don't do this.

Is this a bug or is this expected behavior?

With the current behavior, I end up with interesting data results such as this attached image (after pulling into JavaScript). Note, the single integer is placed directly as a scalar, while the single float value is packed into a single element array.

2020-10-01_17h06_01

I found that changing the float encoding line to:
txt=D_(mat,varargin{:});
yielded what I expect to be correct results.

But I'm curious if there is some other design decision that this change would break?

fangq commented

sorry, did not pay attention to my notifications until now.

I agree this is an inconsistency in the code. I believe this was more of a historical reason why it was written this way.

I made the above commit and it should now output single float value if the SingletArray flag is 0 (default).

let me know if this patch works for you