Creating an array of different data types (integer and float)

7 次查看(过去 30 天)
Hi,
I want to combine two vertical 1D arrays, one of which is a list of numbers from 1 to 10, the other is a list of other numbers which are all decimals. For reference, my variables are n and results and the combined array is A
When I combine them, the integers n into floats (I think that's what they're called) 1.0000, 2.0000 ...etc. I want these to be integers so I try putting A = [int8(n),results]; this changes n to integers but also changes results to integers, which are all zero (I guess it's rounding them down- they are all less than 1).
I've also tried A = {[int8(n),results]}, but this comes up as A = [10x2 int8] in the command window.
Thanks

回答(1 个)

Walter Roberson
Walter Roberson 2013-2-19
It is not possible to have a numeric array that has a mix of datatypes.
Please give the command
format long g
and then re-display (part of) the vertical concatenation to see whether the ".0000" still shows up

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by