Error using == Matrix dimensions must agree
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Here is my code:
I am facing following the error:
File2 =
'BD'
ncell =
[]
Error using ==
Matrix dimensions must agree.
Error in PBM_BR_COAL_app_4_temp/IN_Button (line 395-mentioned in the code as comment %error line%)
B=A(find(row==ncell),:)
I have attached the excel here for clarity of the work. The code will fatch the data from the excel. I am not getting direction out of this error.
function IN_Button(app, event)
[file,path] = uigetfile('*.xls','Select the excel file');
f = fullfile(path,file) ;
app.file.Value=file;app.path.Value=path;
sheet = 'Overall Statistics';
DS = xlsread(f,sheet,'J:J');
% DS=OS(:,9);
DS(find(isnan(DS)))=[];
NF=xlsread(f,sheet,'R:R');%OS(:,17);
NF(find(isnan(NF)))=[];
NF(end)=[];
ind=find(DS>7);
NF(ind)=[];DS(ind)=[];
app.dia=DS;
app.num_freq=NF;
app.dia_in=DS;
app.num_freq_in=NF;
cla(app.NF_fig_ExpData)
% plot(app.NF_fig_ExpData,DS,NF,'-s','DisplayName',string([file,'-Sanja-Stat']))
app.FileEditField.Value=app.file.Value;
% ***************************************
f = 'D:\HMMC\BD.xlsx';
% [file,path] = uigetfile('*.xlsx','Select the excel file');
% f = fullfile(path,file) ;
A = xlsread(f);
file2=app.file.Value;
ind=find(file2=='.');
file2(ind:end)=[]
ncell=str2num(file2(4:end))
row=A(:,1);
B=A(find(row==ncell),:) % error line%
app.TKE.Value=B(2);
app.VF_DF.Value=B(3)/100;
rs=B(4);bs=B(5);
HIST_Button(app, event)
end
2 comentarios
Respuestas (1)
Mohammad Sami
el 19 de Abr. de 2023
Editada: Mohammad Sami
el 19 de Abr. de 2023
I assume you are trying to extract a number from the file name.
Your code assumes that the file name is 4 characters or longer.
It also assumes that numeric value in the filename is starts from character 4 until the end of the filename.
However the file name you use is only 2 chars 'BD' and has no numeric values in it.
A better option would be to use pattern matching rather then using fixed offsets.
You will also need to check that the output is not empty and if there are more then one sequence you will need to see which one you want to use or write a specfic pattern for matching exactly what you require.
More information on pattern is available here R2020b ++
https://www.mathworks.com/help/matlab/ref/pattern.html
For older version of matlab you can use regexp function with regex expression to match what you need.
https://www.mathworks.com/help/matlab/ref/regexp.html?s_tid=doc_ta
a = 'somefile124.xlsx';
p = digitsPattern; % matches one or more digits.
out = extract(a,p)
a = 'somefile_123.456.xlsx'; % multiple digit sequence in the filename
out = extract(a,p)
length(out)
a = 'somefile_nonumber.xlsx';
out = extract(a,p)
length(out)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!