Transfere an excel-list into vectors
    11 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Benedikt Friedrich Nowak
 el 6 de Feb. de 2023
  
    
    
    
    
    Comentada: Benedikt Friedrich Nowak
 el 6 de Feb. de 2023
            Hi there,
im trying to transfere an excel-list into many, specific vectors. Lets say i got three types of metal (x,y,z) and performed two different tests (1,2) on the metal itself. The Results were put in a an excel-list (Picture 1). 
Now i read the excel-list into matlap ("readtable") and want to create different vectors for each metall and each test: 
TypeX_Test1 = [1 2 3]
TypeX_Test2 = [7 8 9]
TypeY_Test1= [15 12 11]
and so on...
How do i make the vectors happen ? 
Thank you for your time and help ! 
Ben 
0 comentarios
Respuesta aceptada
  Tushar Behera
    
 el 6 de Feb. de 2023
        Hi Ben,
I believe you want to bundle up all the metal type and test number into one vector.
This can be acheived by using "regexp" function and by extracting the data from the table and split it into separate variables in MATLAB. I am assuming the table is similar to the picture you have provided. An example for the above workflow will be:
table = readtable('ExampleData.xlsx');
matchingRows = regexp(table.Var1, '^Test 1');
matchingRows = ~cellfun(@isempty, matchingRows);
TypeX_Test1 = table.TypeX(matchingRows);
TypeY_Test1 = table.TypeY(matchingRows);
TypeZ_Test1 = table.TypeZ(matchingRows);
matchingRows2 = regexp(table.Var1, '^Test 2');
matchingRows2 = ~cellfun(@isempty, matchingRows2);
TypeX_Test2 = table.TypeX(matchingRows2);
TypeY_Test2 = table.TypeY(matchingRows2);
TypeZ_Test2 = table.TypeZ(matchingRows2);
%%%%%%%%%%%%%%%%%%%%%%%%%%
Table after extraction
table =
  6×4 table
        Var1        TypeX    TypeY    TypeZ
    ____________    _____    _____    _____
    {'Test 1.1'}      1       15       45  
    {'Test 1.2'}      2       12       42  
    {'Test 1.3'}      3       11       43  
    {'Test 2.1'}      7       19       89  
    {'Test 2.2'}      8       32       90  
    {'Test 2.3'}      9       18       78  
Take a note that in this example the table contains a variable "Var1' which contains the test numbers. 
I hope this resolves your query.
Regards,
Tushar
Más respuestas (0)
Ver también
Categorías
				Más información sobre Spreadsheets en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

