Error Message: Undefined function 'BME3202M2F' for input arguments of type 'char'.

2 Ansichten (letzte 30 Tage)
I cannot get past this error message:
Undefined function 'BME3202M2F' for input arguments of type 'char'.
Error in lab2_exp2_1 (line 10)
[ AI0Centered9, AI1Centered9, time9 ] = BME3202M2F('exp2.1(9).csv',
gain1, gain2);
The function script, usage script, and each of the csv files are saved within the same directory. I tried adding the csv file path into my code as well, but that produced the same error. I've checked the csv files to rule out any issues with empty or corrupted files.
Function Script:
function [ AI0Centered, AI1Centered, time ] = BME3202M2F(filenameStr, gain1, gain2)
data = readmatrix(filenameStr);
time = data(:,1);
AO0 = data(:,2);
AI0 = data(:,3);
AI1 = data(:,4);
% AO0_2_5_index = find(AO0 > 2.5, 1); % 5)
%
% AO0_2_5_time_offset = time(AO0_2_5_index); % 6)
%
% time = time - AO0_2_5_time_offset; % 7) rescale time
%
AI0 = AI0 / gain1; % 8) apply 10 v gain
mean_AI0 = mean(AI0(time <= 0)); % 10)
AI0Centered = AI0 - mean_AI0; % 11) center data
AI1 = AI1 / gain2; % 12) repeat for AI1
mean_AI1 = mean(AI1(time <= 0));
AI1Centered = AI1 - mean_AI1;
figure(3); % 13) create plot
plot(time, AI0Centered, 'r-', 'LineWidth', 2);
hold on;
plot(time, AI1Centered, 'b-', 'LineWidth', 2);
xlabel('Time (s)'); % 14)
ylabel('Response (mV)');
legend('AI0Centered', 'AI1Centered'); % 15)
title(['Data from ' filenameStr]); % 16)
filenameStr = strrep(filenameStr, 'CSV', 'PNG'); % 17) csv to png
saveas(gcf, filenameStr, 'png'); % 18) save png plot
Usage Script:
clc, clear
gain1 = 1000;
gain2 = 1000;
% 9 uA
[ AI0Centered9, AI1Centered9, time9 ] = BME3202M2F('exp2.1(9).csv', gain1, gain2);
AI0Centered9Max = max(AI0Centered9(50:150));
AI0Centered9 = AI0Centered9 * 1000;
% 10 uA
[ AI0Centered10, AI1Centered10, time10 ] = BME3202M2F('/Users/mgaztambide/Documents/MATLAB/BME 3202/Labs/lab 2/exp2.1(10).csv', gain1, gain2);
AI0Centered10Max = max(AI0Centered10(50:150));
AI0Centered10 = AI0Centered10 * 1000;
% 15 uA
[ AI0Centered15, AI1Centered15, time15 ] = BME3202M2F('exp2.1(15).csv', gain1, gain2);
AI0Centered15Max = max(AI0Centered15(50:150));
AI0Centered15 = AI0Centered15 * 1000;
% 18 uA
[ AI0Centered18, AI1Centered18, time18 ] = BME3202M2F('exp2.1(18).csv', gain1, gain2);
AI0Centered18Max = max(AI0Centered18(50:150));
AI0Centered18 = AI0Centered18 * 1000;
% 20 uA
[ AI0Centered20, AI1Centered20, time20 ] = BME3202M2F('exp2.1(20).csv', gain1, gain2);
AI0Centered20Max = max(AI0Centered20(50:150));
AI0Centered20 = AI0Centered20 * 1000;
% 23 uA
[ AI0Centered23, AI1Centered23, time23 ] = BME3202M2F('exp2.1(23).csv', gain1, gain2);
AI0Centered23Max = max(AI0Centered23(50:150));
AI0Centered23 = AI0Centered23 * 1000;
% 27 uA
[ AI0Centered27, AI1Centered27, time27 ] = BME3202M2F('exp2.1(27).csv', gain1, gain2);
AI0Centered27Max = max(AI0Centered27(50:150));
AI0Centered27 = AI0Centered27 * 1000;
% 30 uA
[ AI0Centered30, AI1Centered30, time30 ] = BME3202M2F('exp2.1(30).csv', gain1, gain2);
AI0Centered30Max = max(AI0Centered30(50:150));
AI0Centered30 = AI0Centered30 * 1000;
% 33 uA
[ AI0Centered33, AI1Centered33, time33 ] = BME3202M2F('exp2.1(33).csv', gain1, gain2);
AI0Centered33Max = max(AI0Centered33(50:150));
AI0Centered33 = AI0Centered33 * 1000;
% 36 uA
[ AI0Centered36, AI1Centered36, time36 ] = BME3202M2F('exp2.1(36).csv', gain1, gain2);
AI0Centered36Max = max(AI0Centered36(50:150));
AI0Centered36 = AI0Centered36 * 1000;
% 39 uA
[ AI0Centered39, AI1Centered39, time39 ] = BME3202M2F('exp2.1(39).csv', gain1, gain2);
AI0Centered39Max = max(AI0Centered39(50:150));
AI0Centered39 = AI0Centered39 * 1000;
% 40 uA
[ AI0Centered40, AI1Centered40, time40 ] = BME3202M2F('exp2.1(40).csv', gain1, gain2);
AI0Centered40Max = max(AI0Centered40(50:150));
AI0Centered40 = AI0Centered40 * 1000;
% 45 uA
[ AI0Centered45, AI1Centered45, time45 ] = BME3202M2F('exp2.1(45).csv', gain1, gain2);
AI0Centered45Max = max(AI0Centered45(50:150));
AI0Centered45 = AI0Centered45 * 1000;
% 47 uA
[ AI0Centered47, AI1Centered47, time47 ] = BME3202M2F('exp2.1(47).csv', gain1, gain2);
AI0Centered47Max = max(AI0Centered47(50:150));
AI0Centered47 = AI0Centered47 * 1000;
% 49 uA
[ AI0Centered49, AI1Centered49, time49 ] = BME3202M2F('exp2.1(49).csv', gain1, gain2);
AI0Centered49Max = max(AI0Centered49(50:150));
AI0Centered49 = AI0Centered49 * 1000;
% plot
figure(1);
plot(time9, AI0Centered9, 'r-', 'LineWidth', 2);
hold on;
plot(time27, AI0Centered27, 'b-', 'LineWidth', 2);
hold on;
plot(time49, AI0Centered49, 'g-', 'LineWidth', 2);
xlabel('Time (ms)', 'FontSize', 12)
ylabel('Response Voltage (V)', 'FontSize', 12)
legend('9 uA', '27 uA', '49 uA', 'FontSize', 12)
title('1.1 Raw Data', 'FontSize', 12)
set(gcf,'Position', [0, 0, 6, 4.5]);
saveas(gcf, '2_1rawdataplot', 'png');
AI0CenteredMax = [AI0Centered9Max, AI0Centered10Max, AI0Centered15Max, AI0Centered18Max, AI0Centered20Max, AI0Centered23Max, AI0Centered27Max, AI0Centered30Max, AI0Centered33Max, AI0Centered36Max, AI0Centered39Max, AI0Centered40Max, AI0Centered45Max, AI0Centered47Max, AI0Centered49Max];
AI0CenteredMax = AI0CenteredMax * 1000;
inVar = [9,10,15,18,20,23,27,30,33,36,39,40,45,47,49];
figure(2);
plot(inVar, AI0CenteredMax, 'bo-', 'LineWidth', 2);
xlabel('Stimulation Current (uA)', 'FontSize', 12)
ylabel('Peak Potential (V)', 'FontSize', 12)
title('2.1 Maximum Stimulus Response', 'FontSize', 12)
legend('off')
set(gcf, 'Position', [0, 0, 6, 4.5]);
saveas(gcf, 'stimresponse.png', 'png');

Antworten (1)

Image Analyst
Image Analyst am 1 Okt. 2023
Bearbeitet: Image Analyst am 1 Okt. 2023
It works for me. Watch:
gain1 = 1000;
gain2 = 1000;
% 9 uA
[ AI0Centered9, AI1Centered9, time9 ] = BME3202M2F('exp2.1(9).csv', gain1, gain2);
AI0Centered9Max = max(AI0Centered9(50:150));
AI0Centered9 = AI0Centered9 * 1000;
I think your BME3202M2F.m file is not in the current folder when you run your calling/main script.
After you've run the usage script and gotten the error, tell us what this says in the command window:
>> which -all BME3202M2F
  7 Kommentare
Image Analyst
Image Analyst am 2 Okt. 2023
I believe the current folder is always checked first, so it should have found it. I believe it would only check the search path if it did not find the m-files in the current folder. So even if the path was totally wrong, or the path had in it a folder where your m-file used to live, it should still find it in the current folder unless you were not really in the current folder you thought you were.
Walter Roberson
Walter Roberson am 2 Okt. 2023
... or unless your current folder is one of the MATLAB installation folders: the contents of those are cached and the cache is not re-examined unless you ask it to (or until you add or remove software.)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by