I choose 0 files to construct matrix, all matrix entries are 0
3 次查看(过去 30 天)
显示 更早的评论
I have a code in which person can choose the files from which he can construct matrix with signals, and vector vith a time signal.
I need an additional code for the case if I don't choose the files: respectively files=0, then code should go trough the matrix and vector possitions and plug 0 evrywhere.
clear vector_t_sig simulink_matrix
m=input('how many folders/files you want to use? - ');
files=m;
signal_max=5;
simulink_matrix=cell(files,signal_max);
for i=1:files
[file,path] = uigetfile('MultiSelect','on');
if length(file)>signal_max
file_temp{1}=file;
file=file_temp;
end
for j=1:length(file)
load([path,file{j}])
for k=1:signal_max
if exist('y_inv_L')
position=1;
sig_temp=y_inv_L;
clear y_inv_L;
%and so on for the other possitios%
simulink_matrix{i,position}=sig_temp;
vector_t_sig{i,1}=t_sig;
0 个评论
回答(1 个)
Navya Singam
2021-11-10
Hi,
You may use the if and else block and "zeros" function to add the code for when the number of selected files is 0. zeros function creates an array and it can be converted into cell array using the num2cell function. I have added the additional code required for reference.
clear vector_t_sig simulink_matrix
m=input('how many folders/files you want to use? - ');
files=m;
signal_max=5;
simulink_matrix=cell(files,signal_max);
%% if else block
if files==0 %if number of files is 0, use the zeros function to generate required matrix of all 0's
simulink_matrix = num2cell(zeros(m,n)) %m,n denote the number of rows and column.
vector_t_sig = num2cell(zeros(m,n)) % num2cell function is used for converting numerical array to cell array
else
for i=1:files
[file,path] = uigetfile('MultiSelect','on');
if length(file)>signal_max
file_temp{1}=file;
file=file_temp;
end
for j=1:length(file)
load([path,file{j}])
for k=1:signal_max
if exist('y_inv_L')
position=1;
sig_temp=y_inv_L;
clear y_inv_L;
%and so on for the other possitios%
simulink_matrix{i,position}=sig_temp;
vector_t_sig{i,1}=t_sig;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!