我正在尝试将“细胞”转换为“数据集”而没有成功。我不明白发生了什么以及为什么最明显的Matlab函数cell2dataset
不起作用。也许有人可以解释并帮助我让它发挥作用......
我从csv文件加载输入数据,如下所示:
clc; clear all
filename = '/home/nlv12097/WORK/SSTA_FLOW/CADENV/work/tempus/exp2.ssta2spice/sta_ssta_spectre0/STA_timing.path_output_retime_setup_ssta_full.csv';
fid = fopen(filename); DATA = textscan(fid,'%s%f32%f32%f32%f32%s%f32%s%s%s','delimiter',',','HeaderLines',1); fclose(fid);
DATA
class(DATA)
所以输入数据如下所示:
DATA =
{9x1 cell} [9x1 single] [9x1 single] [9x1 single] [9x1 single] {9x1 cell} [9x1 single] {9x1 cell} {9x1 cell} {9x1 cell}
ans =
cell
重要的是要注意这里DATA被归类为'cell',所以如果我想从中创建一个'dataset'cell2dataset
似乎是合适的函数。正确?
DATASET1 = cell2dataset(DATA,'VarNames',{'VAR1','VAR2','VAR3','VAR4','VAR5','VAR6','VAR7','VAR8','VAR9','VAR10'})
产生以下结果:
DATASET1 =
VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8
{9x1 cell} [9x1 single] [9x1 single] [9x1 single] [9x1 single] {9x1 cell} [9x1 single] {9x1 cell}
VAR9 VAR10
{9x1 cell} {9x1 cell}
这不是我期望看到的。实际上,我希望我的数据集看起来像Matlab文档中的示例。
顺便说一句,如果我这样做:
DATASET2 = mat2dataset(DATA{1},'VarNames',{'VAR1'});
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{2},'VarNames',{'VAR2'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{3},'VarNames',{'VAR3'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{4},'VarNames',{'VAR4'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{5},'VarNames',{'VAR5'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{6},'VarNames',{'VAR6'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{7},'VarNames',{'VAR7'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{8},'VarNames',{'VAR8'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{9},'VarNames',{'VAR9'}));
DATASET2 = horzcat(DATASET2,mat2dataset(DATA{10},'VarNames',{'VAR10'}))
结果是根据我的期望。
DATASET2 =
VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 VAR9
'path4_spi' 57.2 258.2 55.2 3697.3 '89.954 | 40.539' 5000 '3697.299 | 321.456' '4965.247 | 25.811'
'path9_spi' 57.2 258.2 54 3418.8 '90.849 | 40.535' 5000 '3418.800 | 303.210' '4963.150 | 25.804'
'path7_spi' 57.2 258.2 54.2 3483.7 '89.849 | 40.535' 5000 '3483.699 | 309.051' '4964.351 | 25.804'
'path2_spi' 57.2 258.2 55.4 3842.5 '90.758 | 40.554' 5000 '3842.499 | 327.933' '4964.643 | 25.817'
'path8_spi' 57.2 258.2 52.9 3425.2 '89.887 | 40.501' 5000 '3425.200 | 304.215' '4963.013 | 25.786'
'path6_spi' 57.2 258.2 54.4 3629.9 '89.649 | 40.535' 5000 '3629.900 | 316.270' '4964.750 | 25.804'
'path1_spi' 57.2 258.2 55.4 3969.9 '89.658 | 40.554' 5000 '3969.899 | 333.525' '4965.742 | 25.817'
'path3_spi' 57.2 258.2 55.3 3820.1 '89.358 | 40.554' 5000 '3820.100 | 326.701' '4965.942 | 25.817'
'path5_spi' 57.2 258.2 52.7 3623.9 '89.533 | 40.497' 5000 '3623.899 | 316.809' '4963.167 | 25.780'
VAR10
'1267.947 | 322.681'
'1544.351 | 304.491'
'1480.652 | 310.312'
'1122.143 | 329.143'
'1537.813 | 305.491'
'1334.850 | 317.512'
'995.843 | 334.723'
'1145.842 | 327.914'
'1339.268 | 318.047'
但我不喜欢这种方法,因为它涉及可能的代码行。所以我被困在这里。我不知道如何正确使用cell2dataset
,我需要帮助。
Q1:有人关心解释为什么DATASET1和DATASET2不同吗?
Q2:最重要的是如何使用cell2dataset
函数获取DATASET2结果?
答案 0 :(得分:0)
我为提出一个愚蠢的问题而道歉。
在阅读了更多Matlab文档后,我发现了更好的解决方案。实际上,可以直接从输入文件创建数据集。
DATASET3 = dataset('File','/home/nlv12097/WORK/SSTA_FLOW/CADENV/work/tempus/exp2.ssta2spice/sta_ssta_spectre0/STA_timing.path_output_retime_setup_ssta_full.csv','Delimiter',',')
DATASET3 =
Path_Name LaunchFF_CPpin_Time LaunchFF_Qpin_Time CaptureFF_CPpin_Time CaptureFF_Dpin_Time CaptureFF_Response_Time Phase_Shift
'path4_spi' 57.2 258.2 55.2 3697.3 '89.954 | 40.539' 5000
'path9_spi' 57.2 258.2 54 3418.8 '90.849 | 40.535' 5000
'path7_spi' 57.2 258.2 54.2 3483.7 '89.849 | 40.535' 5000
'path2_spi' 57.2 258.2 55.4 3842.5 '90.758 | 40.554' 5000
'path8_spi' 57.2 258.2 52.9 3425.2 '89.887 | 40.501' 5000
'path6_spi' 57.2 258.2 54.4 3629.9 '89.649 | 40.535' 5000
'path1_spi' 57.2 258.2 55.4 3969.9 '89.658 | 40.554' 5000
'path3_spi' 57.2 258.2 55.3 3820.1 '89.358 | 40.554' 5000
'path5_spi' 57.2 258.2 52.7 3623.9 '89.533 | 40.497' 5000
Arrival_Time Required_Time Slack_Time
'3697.299 | 321.456' '4965.247 | 25.811' '1267.947 | 322.681'
'3418.800 | 303.210' '4963.150 | 25.804' '1544.351 | 304.491'
'3483.699 | 309.051' '4964.351 | 25.804' '1480.652 | 310.312'
'3842.499 | 327.933' '4964.643 | 25.817' '1122.143 | 329.143'
'3425.200 | 304.215' '4963.013 | 25.786' '1537.813 | 305.491'
'3629.900 | 316.270' '4964.750 | 25.804' '1334.850 | 317.512'
'3969.899 | 333.525' '4965.742 | 25.817' '995.843 | 334.723'
'3820.100 | 326.701' '4965.942 | 25.817' '1145.842 | 327.914'
'3623.899 | 316.809' '4963.167 | 25.780' '1339.268 | 318.047'