Unrecognized function or variable 'vec2mat'. Error in maynard_rd (line 32) x_n = vec2mat(z, n);

9 views (last 30 days)
function dz = rd(t, z)
% RD Computes the differential equation that describes the update of the
% populations' state following the replicator dynamics
%
% SYNOPSIS: DZ = RD(T, Z)
%
% INPUT T: Time. Although the dynamics are time invariant, this parameter
% might be used to calculate the fitness function
% Z: Vector of the populations' state
%
% OUTPUT DZ: Vector with the value of the differential equation given T and Z
%
% REMARKS Its better to execute first <a href="matlab: help definition">definition</a> and run the game using
% G.run(). This function uses the global variables 'G' and 'norm_dx'
% to define the game
%
% SEE ALSO definition, bnn, logit, maynard_rd, smith, smith_b, stopevent, combined_dynamics
%
% For more information see: <a href="https://github.com/carlobar/PDToolbox_matlab/">the GitHub's repository.</a>
%
% Carlos Barreto, 04-11-16
global G norm_dx
n = max(G.S);
F = zeros(G.P, n);
F_mean = zeros(G.P, 1);
x_dot_v = zeros(G.P* n, 1);
% extract matrix of strategies
x_n = vec2mat(z, n);
x = zeros(G.P, n);
for p = 1 : G.P
x(p, :) = x_n(p, :) * G.m(p);
end
if G.pop_wise == 0
F(:, :) = G.f(x);
else
for p = 1 : G.P
F(p, :) = G.f(x, p);
end
end
for p = 1 : G.P
F_mean(p) = F(p, :) * x_n(p, :)';
% calculate update in the strategy
F_excess = F(p, :) - ones(1, n) * F_mean(p);
x_dot_v ( (p-1)*n + 1 : p*n ) = F_excess .* x_n(p, :);
end
dz = [x_dot_v];
if G.stop_c == true
norm_dx = norm(dz);
end

Answers (2)

Jayanti
Jayanti on 19 Dec 2024
Hi,
The error you're encountering is because MATLAB cannot find the definition of “vec2mat. From the documentation, “vec2mat is not recommended starting from MATLAB R2020a. Instead, you can use “reshape”.
Please refer to following documentation link on “reshape”:
Hope this will resolve the issue!

Torsten
Torsten on 19 Dec 2024
Moved: Torsten on 19 Dec 2024
"vec2mat" is part of the Communications Toolbox. Do you have this toolbox licenced and installed ?

Categories

Find more on Just for fun in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!