Not able to see where the index is going past 5
load(‘Motor_Data.mat’);
fprintf(‘Available motors:n’);
for i = 1:length(Names)
fprintf(‘%d: %sn’, i, Names(i));
end
motor_index = input(‘Select a motor by entering its number: ‘);
mass = input(‘Enter the mass to be lifted (in kg): ‘);
height = input(‘Enter the height to lift the mass (in meters): ‘);
%Says this is where it errors
motor_name = Names(motor_index);
power = Specs(1, motor_index);
efficiency = Specs(2, motor_index);
% Calculate output power
efficiency_decimal = efficiency / 100;
output_power = efficiency_decimal * power;
g = 9.81;
energy_required = mass * g * height;
time = energy_required / output_power;
fprintf(‘Motor: %sn’, motor_name);
fprintf(‘Load lifted: %.2f kgn’, mass);
fprintf(‘Height lifted: %.2f metersn’, height);
fprintf(‘Time to lift the load: %.2f secondsn’, time);
%Task 2
mass = input(‘Enter the mass to be lifted by all motors (in kg): ‘);
height = input(‘Enter the height to lift the mass by all motors (in meters): ‘);
% Initialize results matrix
num_motors = length(Names);
results = zeros(5, num_motors);
% Calculate time for each motor
g = 9.81; % Gravity constant
for i = 1:num_motors
power = Specs(1, i); % Power in watts
efficiency = Specs(2, i); % Efficiency in percentage
efficiency_decimal = efficiency / 100;
output_power = efficiency_decimal * power;
% Energy required to lift mass
energy_required = mass * g * height;
% Time to lift
time = energy_required / output_power;
% Store results: power, efficiency, mass, height, time
results(:, i) = [power; efficiency; mass; height; time];
end
% Export results to CSV file
csvwrite(‘Task2_Results.csv’, results);
% Display the matrix to verify
disp(‘Results matrix:’);
disp(results);
%Task 3
output_powers = Specs(1, 🙂 .* (Specs(2, 🙂 / 100); % Output power for each motor
times = results(5, :); % Time from the results matrix
scatter(output_powers, times, ‘filled’);
xlabel(‘Output Power (W)’);
ylabel(‘Time to Lift Load (s)’);
title(‘Motor Output Power vs. Time to Lift Load’);
grid on;load(‘Motor_Data.mat’);
fprintf(‘Available motors:n’);
for i = 1:length(Names)
fprintf(‘%d: %sn’, i, Names(i));
end
motor_index = input(‘Select a motor by entering its number: ‘);
mass = input(‘Enter the mass to be lifted (in kg): ‘);
height = input(‘Enter the height to lift the mass (in meters): ‘);
%Says this is where it errors
motor_name = Names(motor_index);
power = Specs(1, motor_index);
efficiency = Specs(2, motor_index);
% Calculate output power
efficiency_decimal = efficiency / 100;
output_power = efficiency_decimal * power;
g = 9.81;
energy_required = mass * g * height;
time = energy_required / output_power;
fprintf(‘Motor: %sn’, motor_name);
fprintf(‘Load lifted: %.2f kgn’, mass);
fprintf(‘Height lifted: %.2f metersn’, height);
fprintf(‘Time to lift the load: %.2f secondsn’, time);
%Task 2
mass = input(‘Enter the mass to be lifted by all motors (in kg): ‘);
height = input(‘Enter the height to lift the mass by all motors (in meters): ‘);
% Initialize results matrix
num_motors = length(Names);
results = zeros(5, num_motors);
% Calculate time for each motor
g = 9.81; % Gravity constant
for i = 1:num_motors
power = Specs(1, i); % Power in watts
efficiency = Specs(2, i); % Efficiency in percentage
efficiency_decimal = efficiency / 100;
output_power = efficiency_decimal * power;
% Energy required to lift mass
energy_required = mass * g * height;
% Time to lift
time = energy_required / output_power;
% Store results: power, efficiency, mass, height, time
results(:, i) = [power; efficiency; mass; height; time];
end
% Export results to CSV file
csvwrite(‘Task2_Results.csv’, results);
% Display the matrix to verify
disp(‘Results matrix:’);
disp(results);
%Task 3
output_powers = Specs(1, 🙂 .* (Specs(2, 🙂 / 100); % Output power for each motor
times = results(5, :); % Time from the results matrix
scatter(output_powers, times, ‘filled’);
xlabel(‘Output Power (W)’);
ylabel(‘Time to Lift Load (s)’);
title(‘Motor Output Power vs. Time to Lift Load’);
grid on;Â load(‘Motor_Data.mat’);
fprintf(‘Available motors:n’);
for i = 1:length(Names)
fprintf(‘%d: %sn’, i, Names(i));
end
motor_index = input(‘Select a motor by entering its number: ‘);
mass = input(‘Enter the mass to be lifted (in kg): ‘);
height = input(‘Enter the height to lift the mass (in meters): ‘);
%Says this is where it errors
motor_name = Names(motor_index);
power = Specs(1, motor_index);
efficiency = Specs(2, motor_index);
% Calculate output power
efficiency_decimal = efficiency / 100;
output_power = efficiency_decimal * power;
g = 9.81;
energy_required = mass * g * height;
time = energy_required / output_power;
fprintf(‘Motor: %sn’, motor_name);
fprintf(‘Load lifted: %.2f kgn’, mass);
fprintf(‘Height lifted: %.2f metersn’, height);
fprintf(‘Time to lift the load: %.2f secondsn’, time);
%Task 2
mass = input(‘Enter the mass to be lifted by all motors (in kg): ‘);
height = input(‘Enter the height to lift the mass by all motors (in meters): ‘);
% Initialize results matrix
num_motors = length(Names);
results = zeros(5, num_motors);
% Calculate time for each motor
g = 9.81; % Gravity constant
for i = 1:num_motors
power = Specs(1, i); % Power in watts
efficiency = Specs(2, i); % Efficiency in percentage
efficiency_decimal = efficiency / 100;
output_power = efficiency_decimal * power;
% Energy required to lift mass
energy_required = mass * g * height;
% Time to lift
time = energy_required / output_power;
% Store results: power, efficiency, mass, height, time
results(:, i) = [power; efficiency; mass; height; time];
end
% Export results to CSV file
csvwrite(‘Task2_Results.csv’, results);
% Display the matrix to verify
disp(‘Results matrix:’);
disp(results);
%Task 3
output_powers = Specs(1, 🙂 .* (Specs(2, 🙂 / 100); % Output power for each motor
times = results(5, :); % Time from the results matrix
scatter(output_powers, times, ‘filled’);
xlabel(‘Output Power (W)’);
ylabel(‘Time to Lift Load (s)’);
title(‘Motor Output Power vs. Time to Lift Load’);
grid on; matlab MATLAB Answers — New Questions
​