I am unable to make the code work
显示 更早的评论
clc;
A = perturbation_sample_generator(2, 1000, 12345); %% Pertubation samples for IM=2
B = perturbation_sample_generator(4, 1000, 12345); %% Pertubation samples for IM=4
C = perturbation_sample_generator(6, 1000, 12345); %% Pertubation samples for IM=6
D = perturbation_sample_generator(8, 1000, 12345); %% Pertubation samples for IM=8
E = perturbation_sample_generator(10, 1000, 12345); %% Pertubation samples for IM=10
F = perturbation_sample_generator(12, 1000, 12345); %% Pertubation samples for IM=12
function [perturnation_sample] = perturbation_sample_generator(IM, N_samples, random_seed)
end
% Function to generate samples of a system perturbation.
%
% Syntax: [perturbation_samples] = perturbation_sample_generator(IM, N_samples, random_seed)
% "perturbation_samples" is an output matrix with each column corresponding to a different sample of the perturbation
% "IM" is the level of the intensity measure at which the samples are generated
% "N_samples" is the number of samples to be generated
% "random_seed" is an arbitrary integer that sets the random number generator and enables reproducibility of the results
%
% Coded by Dr. Paolo Bocchini for the course "Catastrophe Modeling and Resilience"
% Lehigh University
%
% Note: the actual code is in the p-file, the m-file is provided only to offer syntax help.
2 个评论
Torsten
2022-10-9
We don't know the function "perturbation_sample_generator". So how could we be able to help ?
dpb
2022-10-9
Indeed.
But, what error did you get, just for grins?
One think can think of would be if didn't save the p-file along with the m-file or didn't put it in a location on the MATLABPATH or in local pwd. Then could see the help but that'd be all; get error about the missing p-file when try to use it.
回答(2 个)
Walter Roberson
2022-10-9
function [perturnation_sample] = perturbation_sample_generator(IM, N_samples, random_seed)
end
With the end being right there, you have a function that accepts up to 3 inputs and immediately returns without doing any work. In particular, it is without doing any assignment to the output variable, perturnation_sample . That is a problem because you try to assign the output of a function to a variable, but there is no output.
% Note: the actual code is in the p-file, the m-file is provided only to offer syntax help.
if you had a perturbation_sample_generator.p on the MATLAB path, at the same location or earlier in the path compared to perturbation_sample_generator.m then the .p file would take priority, and calculate whatever needed to be calculated.
However, if you are missing the .p file or it is later in the path than the perturbation_sample_generator.m file then you would have the problem I described above of the .m code not returning any value.
I suspect that you are missing the perturbation_sample_generator.p file.
Image Analyst
2022-10-9
0 个投票
Can we assume that you have perturbation_sample_generator.p (not .m!!!!) in your current folder or somewhere on your path? What does this show
>> which -all perturbation_sample_generator
so, if you have the p file, what happens if you comment out the "function" line and the "end" line in your script so that it calls the perturbation_sample_generator from the p-file rather than the (essentially null) perturbation_sample_generator() function in your script? Does it run then?
1 个评论
dpb
2022-10-9
>> which -all testit
C:\Users\Duane\Documents\MATLAB\Work\testit.p
C:\Users\Duane\Documents\MATLAB\Work\testit.m % Shadowed
>>
The p-file should shadow the m-file of the same name -- it won't only if it isn't on the search path to be found first.
Hmmm...I suppose it could be there but in a path farther down the search order --
>> movefile testit.p ..\Utilities\testit.p
>> dir testit.*
testit.m
>> which -all testit
C:\Users\Duane\Documents\MATLAB\Work\testit.m
C:\Users\Duane\Documents\MATLAB\Utilities\testit.p % Shadowed
>>
Nope...if it is on MATLABPATH at all, the hashing happens on a complete search first...thought so, but just to check.
>> movefile ..\Utilities\testit.p C:\Users\Duane\Documents\ f
>> rehash
>> which -all testit
C:\Users\Duane\Documents\MATLAB\Work\testit.m
>>
So, that fails now...as the base directory isn't on the MATLABPATH.
m-files for help for builtin functions don't contain any executable code but end with the
% Built-in function.
If the m-file for a p-code function is missing, the p-code function still runs but any help text in the m-file is unavailable; the interpreter for p-code stub will output
testit is a function.
类别
在 帮助中心 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!