Why am I getting an error 'Execution of script cosamp as a function is not supported'

조회 수: 3 (최근 30일)
%% Generate signal, DCT of signal
n = 4096; % points in high resolution signal
t = linspace(0, 1, n);
x = cos(2* 97 * pi * t) + cos(2* 777 * pi * t);
xt = fft(x); % Fourier transformed signal
PSD = xt.*conj(xt)/n; % Power spectral density
% Randomly sample signal
p = 128; % num. random samples, p=n/32
perm = round(rand(p, 1) * n);
y = x(perm); % compressed measurement
% Solve compressed sensing problem
Psi = dct(eye(n, n)); % build Psi
Theta = Psi(perm, :); % Measure rows of Psi
s = cosamp(Theta,y,10,1.e-10,10); % CS via matching pursuit
xrecon = idct(s); % reconstruct full signal
  댓글 수: 2
Chris
Chris 2021년 11월 1일
What is cosamp? If it's a FileExchange function, are you capitalizing letters appropriately? If it's something you made, is it a function that accepts inputs and returns an output?

댓글을 달려면 로그인하십시오.

답변 (2개)

Elghandouri Mohammed
Elghandouri Mohammed 2022년 1월 25일
Hi.
Please, have you solved this problem or not? I have the same problem, I don’t know how I can solve it.
Thank you.
  댓글 수: 3
Elghandouri Mohammed
Elghandouri Mohammed 2022년 1월 25일
You can copy the code below in your script and saved it like a function under the name 'cosamp'
%%
function Sest = cosamp(Phi,u,K,tol,maxiterations)
% Cosamp algorithm
% Input
% K : sparsity of Sest
% Phi : measurement matrix
% u: measured vector
% tol : tolerance for approximation between successive solutions.
% Output
% Sest: Solution found by the algorithm
%
% Algorithm as described in "CoSaMP: Iterative signal recovery from
% incomplete and inaccurate samples" by Deanna Needell and Joel Tropp.
%
% This implementation was written by David Mary,
% but modified 20110707 by Bob L. Sturm to make it much clearer,
% and corrected multiple times again and again.
% To begin with, see: http://media.aau.dk/null_space_pursuits/2011/07/ ...
% algorithm-power-hour-compressive-sampling-matching-pursuit-cosamp.html
%
% This script/program is released under the Commons Creative Licence
% with Attribution Non-commercial Share Alike (by-nc-sa)
% http://creativecommons.org/licenses/by-nc-sa/3.0/
% Short Disclaimer: this script is for educational purpose only.
% Longer Disclaimer see http://igorcarron.googlepages.com/disclaimer
% Initialization
Sest = zeros(size(Phi,2),1);
v = u;
t = 1;
numericalprecision = 1e-12;
T = [];
while (t <= maxiterations) && (norm(v)/norm(u) > tol)
y = abs(Phi'*v);
[vals,z] = sort(y,'descend');
Omega = find(y >= vals(2*K) & y > numericalprecision);
T = union(Omega,T);
b = pinv(Phi(:,T))*u;
[vals,z] = sort(abs(b),'descend');
Kgoodindices = (abs(b) >= vals(K) & abs(b) > numericalprecision);
T = T(Kgoodindices);
Sest = zeros(size(Phi,2),1);
b = b(Kgoodindices);
Sest(T) = b;
v = u - Phi(:,T)*b;
t = t+1;
end;
Elghandouri Mohammed
Elghandouri Mohammed 2022년 1월 25일
You should verify the dimension of your matrix theta and the vector y.
May be you have also another script called cosamp.m somewhere in your Matlab path, which Matlab is attempting to run, then you should rename this script or move it.

댓글을 달려면 로그인하십시오.


Chris
Chris 2022년 1월 25일
편집: Chris 2022년 1월 25일
Using the function provided by @Elghandouri Mohammed and the original script, the error I get is:
Error using _*_
Incorrect dimensions for matrix multiplication. ...
That can be remedied by transposing y, so that its dimensions correlate with Theta's dimensions:
s = cosamp(Theta,y',10,1.e-10,10);
If you are still getting 'Execution of script cosamp as a function is not supported'
Then there is a script called cosamp.m somewhere in your Matlab path, which Matlab is attempting to run.
type which cosamp in the Matlab Command Window to locate it, and rename it or remove it from Matlab's path.
  댓글 수: 1
Elghandouri Mohammed
Elghandouri Mohammed 2022년 1월 25일
편집: Elghandouri Mohammed 2022년 1월 25일
The function is working good for me, maybe you should close your Matlab map and open it again.
You should also save the function cosmap.m in the folder where your script program is saved, and remove the old function named cosmap.m

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by