Command Function will not accept the script name. I have tried changing the function name so it is different from the script but this still does not work.
이전 댓글 표시
%Setup Matlab Script
clear
close all
clc
function plotctd(datafilename)
Data = dlmread(datafilename,'',117,1);
Depth=Data(:,1);
Salinity=Data(:,2);
Temp=Data(:,3);
%calculating density
Density=sw_dens0(Salinity,Temp);
%Subplot of data
subplot(1,3,1)
plot(Temp,Depth,'k-+')
set(gca,'YDir','reverse')
xlabel('Temperaure (^oC)')
ylabel('Depth (m)')
grid
subplot(1,3,2)
plot(Salinity,Depth,'k-+')
set(gca,'YDir','reverse')
xlabel('Salinity (PSU)')
grid
title(datafilename)
subplot(1,3,3)
plot(Density,Depth,'k-+')
set(gca,'YDir','reverse')
xlabel('Density (kg/m^3)')
grid
plotctd('D1.cnv')
end
This code gives me the error message:
File: plotctd.m Line: 6 Column: 10
Local function name must be different from the script name.
답변 (1개)
Walter Roberson
2022년 2월 9일
clear
close all
clc
Delete those lines.
댓글 수: 5
Luke Ainsworth
2022년 2월 9일
Steven Lord
2022년 2월 9일
Please show us the exact line of code you're using to try to run your function and the full and exact text (everything displayed in red and/or orange in the Command Window) of the error and/or warning messages you receive when you run that exact line of code. This information may help us understand why MATLAB throws an error.
Luke Ainsworth
2022년 2월 9일
Walter Roberson
2022년 2월 9일
편집: Walter Roberson
2022년 2월 9일
It would be easier on the volunteers if you were to post code instead of posting pictures of code.
Delete your current line 31, which reads
plotctd(D1.cnv)
Now, create a new file, perhaps plot_D1.m that contains
plotctd('D1.cnv')
and execute that file.
Stephen23
2022년 2월 10일
@Luke Ainsworth: you have defined a recursive function which only stops because of invalid input data.
Solution: do not call PLOTCTD inside the function PLOTCTD.
You also need to call the function with a valid filename as its input argument.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
