CSV Write to specific column
2 次查看(过去 30 天)
显示 更早的评论
Hello, Please find the model & expected output in the csv/excel file. What I want to do os to find out no of blocks in the model, get input output ports of each block, list them in excel/CSV, & write corrosponding I or O before each signal as shown in the fig attahced.Please help
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156522/image.jpeg)
I have written the following script
clc; %Get all blocks in side the model blks = find_system(gcb,'SearchDepth','1','LookUnderMasks','all','BlockType','SubSystem'); names = get_param(blks,'Name');
%Define & write header
header = {'Signal Name','A','B','C','D'};
xlswrite('PreDD.xls',header,'DD_Data','A1');
% lmwrite('PreDD.csv',header,0,0);
tdta = [];
inportdata = [];
outportdata = [];
index = 1;
%read data from the model
for a = 2 : size(blks)
load_system(char(blks(a)));
inports = find_system(char(blks(a)),'LookUnderMasks','all','BlockType','Inport');
outports = find_system(char(blks(a)),'LookUnderMasks','all','BlockType','Outport');
in_nms = get_param(inports,'Name');
ot_nms = get_param(outports,'Name');
inportdata = [inportdata;names(a);in_nms];
outportdata = [outportdata;names(a);ot_nms];
tdta = [tdta;in_nms;ot_nms]; %signal list of a subsystems
data = unique(tdta);
cname = inportdata(index);
cpos = strmatch(cname,header, 'exact');
rpos = strmatch(inportdata(index+1),data,'exact');
end
xlswrite('PreDD.xls',data,'DD_Data','A2');
winopen('PreDD.xls');
PLEASE NOTE THAT A TOP LEVEL SUBSYSTEM IS CREATED AS 'TEST' & SELECTING THAT SUBSYSTEM SCRIPT IS RUN.
what I am getting currently is as follows
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156524/image.jpeg)
What I required is as follows
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156525/image.jpeg)
please note that the data should appear in independent column as shown below
Please help ASAP, thanks in advance!! Sameer
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!