check out a matlab code method
32 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I'm deeply sorry to ask this question, because i could'nt resolve it . I'm using R2024a matlab version, and I wanna know how to check a matlab code i mean ( array, matrix,...) . In this part, I would know how to get those errors messages?
if Bearing_Type == 7 % fluid film bearings - based on short width bearing theory
if ncol_bearing < 7, disp('>>>> Error - too few columns in bearing definition matrix for bearing type 7'), end
if Rotor_Spd == 0, disp('>>>> Error - bearing type 7 - fluid bearing model undefined at zero speed'), end
F = Bearing_Def(i,3); % static load (N) colonne 3,The static bearing's force needs to be calculated.
D = Bearing_Def(i,4); % bearing diameter (m) colonne 4
L = Bearing_Def(i,5); % bearing length (m) colonne 5
c = Bearing_Def(i,6); % bearing radial clearance (m) colonne 6
eta = Bearing_Def(i,7); % oil viscosity (Ns/m^2) colonne 7
model.bearing = [7 1 Bearing1_diam Bearing1_clear Bearing1_wid Lubricating_oil_number eta; ...
7 12 Bearing2_diam Bearing2_clear Bearing2_wid Lubricating_oil_number eta];
1 个评论
Walter Roberson
2025-11-15,21:12
If the conditions such as ncol_bearing<7 is met, then you emit an error message, and continue on in the code, including the assignment to model.bearing. I would suggest that if the error messages are omitted, that you want to skip the assignments. Consider using an if / elseif / else structure, or consider using assert
回答(2 个)
dpb
2025-11-16,15:18
编辑:dpb
2025-11-20,20:23
Would be more helpful to see more of the function context, but a couple of recommendations
Firstly, for the diagnostics, parameter validation portion, look at the <Arguments Definitions> section and the <arguments> block.
Secondly it would make using the function and argument list far simpler it you were to use a struct or object definition for the bearings and then an array of those rather than having so many individually-named like variables. Using sequentially numbered variable names such as you have is generally a sign of not using the power of MATLA vector operations which is the strong point of the language.
TYPES={7,7};
DIAMS={diam1,diam2};
CLEAR={clear1. clear2};
WIDTH={wid1, wid2};
OIL=Lubricating_oil_number;
ETA=eta;
Bearings=struct('Type',TYPES,'Diam',DIAMS,'Clearance',CLEARS,'Width',WIDTH,'LubeOil',Oil,'Eta',ETA);
Then you can just pass the Bearings struct array. with all the needed informtion defining each bearing and then what other specific arguments individually.
0 个评论
Image Analyst
2025-11-16,16:09
It helps if you indent your code properly and put one line of code per line. Try this:
if Bearing_Type == 7 % fluid film bearings - based on short width bearing theory
% First, validate input parameters, exiting if any is wrong.
if ncol_bearing < 7
errordlg('>>>> Error - too few columns in bearing definition matrix for bearing type 7')
return; % No sense in continuing after an error.
end
if Rotor_Spd == 0
errordlg('>>>> Error - bearing type 7 - fluid bearing model undefined at zero speed')
return; % No sense in continuing after an error.
end
% If you get this far, all is good.
F = Bearing_Def(i,3); % static load (N) colonne 3,The static bearing's force needs to be calculated.
D = Bearing_Def(i,4); % bearing diameter (m) colonne 4
L = Bearing_Def(i,5); % bearing length (m) colonne 5
c = Bearing_Def(i,6); % bearing radial clearance (m) colonne 6
eta = Bearing_Def(i,7); % oil viscosity (Ns/m^2) colonne 7
model.bearing = [7 1 Bearing1_diam Bearing1_clear Bearing1_wid Lubricating_oil_number eta; ...
7 12 Bearing2_diam Bearing2_clear Bearing2_wid Lubricating_oil_number eta];
end % of if Bearing_Type == 7
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!