Transfere an excel-list into vectors
    조회 수: 11 (최근 30일)
  
       이전 댓글 표시
    
    Benedikt Friedrich Nowak
 2023년 2월 6일
  
    
    
    
    
    댓글: Benedikt Friedrich Nowak
 2023년 2월 6일
            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
채택된 답변
  Tushar Behera
    
 2023년 2월 6일
        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
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

