Borrar filtros
Borrar filtros

finding the name which are the same in an Excell file and make structure and sub-structure form them

3 visualizaciones (últimos 30 días)
Hi everyone! I'm lerning Matlab and work with structur types . I appreciated if you help me with my problem. i read about unique but need help. Here is my question i have a (n x 3) matrix or better say an Excel file with 3 column and many rows it look like this:
Name time value
AA t1 v1
BB t2 v2
CC t3 v3
AA t4 v4
DD t5 v5
AA t6 v6
BB t7 v7
And so on. Now I must find all the name that are the same ,make Structure from them and as sub-structure it should contain the times and the values of that specified name ,so that it should be like this:
Let say this excel file calles excel_file and the main structure called str , so str.name will be names in first row :
str.names= excel_file( : , 1 )
Now I don’t know how to gather the values and times as sub-structure for each names . as example
str.AA should contain a substructure which this sub-struct contains all the infos about AA which are t1,v1 , t4,v4 and t6,v6
And so on for str.BB : t2,v2 -t7,v7 and str.CC t3,v3 and str.DD t5,v5
the Names are acually signals which are happend in different times and every signal has different value . it's mean in the Excel file will be many equal signal_names which are happend in different times and have different value .And the data should just be sorted in structure and sub structurs and the goal is that ,when i call a specified signal_name as a structure ,I shoud be able to see a sub structure containg all the Times and value for this signal_name
in an other way str.name is actually a (n,1) big matrix . and n is number of different names. so if the exell has 100 rows( as 100 names ) there are as example n=70 different names in it.
also str.name has two substructures str.name.time and str.name.value , both of these two are (m,1) big, but m is different for each str.name becaues names are repeated differently
Or in an other way i want to know that in which times ist the name AA happened and what are the value and so on for other names
Thank you for your help in advance
  9 comentarios
Milad Ghobadi
Milad Ghobadi el 9 de En. de 2020
Thank you . But the goal is to gather all the values and times with same signal namen in a sub structure
Guillaume
Guillaume el 9 de En. de 2020
"But the goal is to gather all the values and times with same signal namen in a sub structure"
No, that's a not a goal. You're again making the mistake of describing an implementation of a goal, not the goal itself. As we've said many times now, using structures is most likely the wrong approach.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 8 de En. de 2020
From your description, it really sounds like you would be better off using a table rather than splitting the data into structures. Tables are much easier to work with. Something like this should get you started:
sourcefile = 'C:\somewhere\somefolder\somefile.xlsx';
signaldata = readtable(yoursourcefile); %probably works out of the box if your excel file is well structured. Can be customised if needed to cope with more complicated files
%the following assumes that the excel file has a header row containing 'Name', 'Time', 'Signal'
signaldata = sortrows(signaldata, 'Name', 'Time'); %optional: reorder the rows, first by name, then by time, for easier visualisation
With that it's straightforward to filter on a particular signal
signaldata(strcmp(signaldata.Name, 'AA', :) %get section of table corresponding to signal AA
or plot the evolution of each signal against time:
figure; hold('on');
rowfun(@plot, signaldata, 'GroupingVariables', 'Name'); %plot Value VS Time for each signal
or for an even better plot:
figure; hold('on');
rowfun(@(n, t, v) plot(t, v, 'DisplayName', n{1}), signaldata, 'GroupingVariables', 'Name', 'InputVariables', 1:3); %plot Value VS Time for each signal
legend('show')

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by