Error using == Matrix dimensions must agree

1 visualizzazione (ultimi 30 giorni)
Manthan
Manthan il 19 Apr 2023
Commentato: Manthan il 19 Apr 2023
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 Commenti
KSSV
KSSV il 19 Apr 2023
What exactly you are trying to do from the excel file data?
Manthan
Manthan il 19 Apr 2023
I am working on the GUI that takes data (excel file) and return to back end code.
GUI image is attached

Accedi per commentare.

Risposte (1)

Mohammad Sami
Mohammad Sami il 19 Apr 2023
Modificato: Mohammad Sami il 19 Apr 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)
out = 1×1 cell array
{'124'}
a = 'somefile_123.456.xlsx'; % multiple digit sequence in the filename
out = extract(a,p)
out = 2×1 cell array
{'123'} {'456'}
length(out)
ans = 2
a = 'somefile_nonumber.xlsx';
out = extract(a,p)
out = 0×1 empty cell array
length(out)
ans = 0
  1 Commento
Manthan
Manthan il 19 Apr 2023
Thank you for the response. What I am trying to do is the GUI will take data inside the excel file and return it to backend code.

Accedi per commentare.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by