Help with storing data in a 4-D double matrix

1 vue (au cours des 30 derniers jours)
Jake
Jake le 20 Déc 2022
Modifié(e) : Jake le 21 Déc 2022
I have a data set in the form of 8 columns. I have attached a dummy xlsx file to show the data structure.
As it can be seen, the data set includes [time, frequency, idx, node number, V1, V2, V3, V4]. I'm trying to sort and store these in a way such that I can access V3 values of a particular frequency and of a particular time. Purpose is to be able to access V3 values of a given time/frequency.
What I thought of the structure was something like this.
Re_vx = zeros(length(node_no), 2, length(time), length(frequency));
So I get a matrix in the form of (node_no, V3, time_set, freq_set).
How can I go about this? TIA!

Réponses (1)

Voss
Voss le 20 Déc 2022
How about storing that data set as a table:
t = readtable('new1.xlsx');
t = renamevars(t,t.Properties.VariableNames, ...
{'time','frequency','idx','node_no','V1','V2','V3','V4'})
t = 144×8 table
time frequency idx node_no V1 V2 V3 V4 ______ _________ ___ _______ _________ ________ _________ ________ 1.0472 0.1 1 1 0.2377 0.26627 0.75846 0.31877 1.0472 0.1 1 2 0.60871 0.54889 0.64385 0.088389 1.0472 0.1 1 3 0.82648 0.45033 0.38874 0.16956 1.0472 0.1 1 4 0.29342 0.23107 0.64533 0.44209 1.0472 0.1 1 5 0.26534 0.34716 0.0031364 0.681 1.0472 0.1 1 6 0.75924 0.93866 0.36407 0.27537 1.0472 0.1 1 7 0.0079028 0.33617 0.036416 0.19378 1.0472 0.1 1 8 0.46993 0.47571 0.86852 0.35832 1.0472 0.1 1 9 0.44592 0.90444 0.2673 0.30641 1.0472 0.1 1 10 0.84343 0.07228 0.19927 0.94522 1.0472 0.1 1 11 0.44459 0.078301 0.37323 0.12497 1.0472 0.1 1 12 0.94596 0.50363 0.71822 0.21068 1.0472 0.2 1 1 0.58522 0.48479 0.26291 0.72812 1.0472 0.2 1 2 0.83658 0.77427 0.60219 0.23663 1.0472 0.2 1 3 0.44332 0.1263 0.62431 0.057136 1.0472 0.2 1 4 0.11618 0.84017 0.84411 0.1615
And using logical indexing to get the values at a particular time and frequency:
my_time = t.time(15)
my_time = 1.0472
my_freq = t.frequency(15)
my_freq = 0.2000
result = t(t.time == my_time & t.frequency == my_freq,:)
result = 12×8 table
time frequency idx node_no V1 V2 V3 V4 ______ _________ ___ _______ ________ ________ _______ ________ 1.0472 0.2 1 1 0.58522 0.48479 0.26291 0.72812 1.0472 0.2 1 2 0.83658 0.77427 0.60219 0.23663 1.0472 0.2 1 3 0.44332 0.1263 0.62431 0.057136 1.0472 0.2 1 4 0.11618 0.84017 0.84411 0.1615 1.0472 0.2 1 5 0.1831 0.86732 0.65839 0.53164 1.0472 0.2 1 6 0.090321 0.091064 0.64369 0.63566 1.0472 0.2 1 7 0.24416 0.29224 0.88131 0.76682 1.0472 0.2 1 8 0.54519 0.64255 0.87907 0.47458 1.0472 0.2 1 9 0.10051 0.85658 0.65277 0.45944 1.0472 0.2 1 10 0.87678 0.076611 0.94155 0.34647 1.0472 0.2 1 11 0.59088 0.54855 0.5428 0.99147 1.0472 0.2 1 12 0.31276 0.83399 0.76469 0.8957
result.V3
ans = 12×1
0.2629 0.6022 0.6243 0.8441 0.6584 0.6437 0.8813 0.8791 0.6528 0.9416
  1 commentaire
Jake
Jake le 21 Déc 2022
Modifié(e) : Jake le 21 Déc 2022
Thank you for the response, Voss. This works when I know the specific time or a frequency that I need the V3 values of. But I wanted to get these sorted in a way that I can access them rather easily. For example, say I want to access the V3 values of frequency f1, f2, f3 but within the time t1. If I had the desired matrix (following the dummy image I attached above), those would be val(:,:,1,1), val(:,:,2,1), val(:,:,3,1).
Also, my dataset is pretty large too :( Anyway, thank you so much for the response.
EDIT:
I realized my comment and the question I posted have some contradicting points. What I wanted is to store the values in a matrix in the form of (node_no, V3, time_set, freq_set). So, if I want to get all the V3 values of the 1st time period I can access it simply by Re_vx(:,:,1,:), or at least that's what I imagined. There should be more efficient or better ways to achieve this, and I appreciate any suggestion! :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by