I choose 0 files to construct matrix, all matrix entries are 0

조회 수: 1 (최근 30일)
Márcis Pinups
Márcis Pinups 2021년 11월 3일
답변: Navya Singam 2021년 11월 10일
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;

답변 (1개)

Navya Singam
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;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by