Loading a zero array without setting as "empty"

Hi,
I am reading a data array (Data_Input) approx 32000 x 24 into 24 seperate arrays for easy plotting.
Firstly, I initialize each target array: (just one shown for simplicity):
app.Data1=zeros(number_of_rows,1,'double');
app.Data1 = app.Data_Input(:,4); This loads the 4th column from Data_Input into app.Data1, and works fine!
However, the problem is when app.Data_Input(:,4) (i.e. the 4th column) is full of zeros.
Then, instead of the initialized app.Data1 "zeros" matrix, I now have app.Data1 = empty !
This completely confuses my later APP software as it can't extract the "0" values from specific rows.
So how can I prevent a nicely formatted zeros matrix being converted to an "empty" matrix?
Please help,
Thanks

5 commentaires

"... into 24 seperate arrays for easy plotting."
Why not utilize functionalities of plot? or use a for loop?
%E.g. plotting a vector against a matrix -
x = rand(1,10);
y = rand(4,10);
plot(sort(x),y)
Matt J
Matt J le 9 Fév 2024
So how can I prevent a nicely formatted zeros matrix being converted to an "empty" matrix?
It is not at all clear why that would happen, unless you have defined a method set.Data1() which specifically converts app.Data1 to [] in that special case.
SteveM
SteveM le 9 Fév 2024
Hi Matt,
I don't undertsand why a zeros matrix is replaced with an "empty" matrix, but it does seem to happen if the index in the incoming array has an error. Then without crashing (or jumping to a catch) an empty matrix is created, which then replaces the zeros matrix. Anyway, now I undertsand why, I have changed the code to protect the matrix index from going out of range.
Thanks
Josh,
I want seperate matrices as I need to perform other operations solely on one column. It makes it much easier for subsequent code (and more readable) and runs faster if split into 24 separate matrices at the start.
cheers
Steve
"I want seperate matrices as I need to perform other operations solely on one column."
That can be done via indexing as well.
"... runs faster if split into 24 separate matrices at the start."
I doubt that.
A simple approach would be to read the data, perform the operation on that particular column and then plot accordingly.
As I mentioned above and is explained thoroughly in the link I attached, splitting data into separate matrices is not considered to be a good idea.
app.Data1
A cell array with indexing would still probably be better than 24 fields with pseudo-indices in their names.
@Dyuman Joshi: the code in the OP's question does not show 24 separate variables in the workspace (but apparently has 24 different fields of some app), so my tutorial is not directly related.

Connectez-vous pour commenter.

Réponses (0)

Catégories

Tags

Question posée :

le 9 Fév 2024

Commenté :

le 9 Fév 2024

Community Treasure Hunt

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

Start Hunting!

Translated by