Azzera filtri
Azzera filtri

change size[ 3 1] to [3 25]

1 visualizzazione (ultimi 30 giorni)
Haiwen Sun
Haiwen Sun il 28 Ott 2020
a = [1 4 -2];
strColors = {'-r', '-g', '-b'};
for k=1:length(a)
LabFc3 = @(x)sin((a(k)/2)*pi*x).*(a(k)*x.^2+3);
fplot(LabFc3,[-8 8],strColors{k});
funcOut(k,:) = LabFc3(a(k)); linspace(-8,randi([0,8],1,1),25);
hold on;
end
This is my code here. In my instruction, it only gives me [1 4 -2] these three values. Everything is fine besides the funcOut size is [3 1], it requires [3 25]. How could I fix this?

Risposte (1)

Sourabh Kondapaka
Sourabh Kondapaka il 6 Nov 2020
If we pre-allocate funcOut matrix of size 3 x 25, we can get the output you are trying to achieve. This is happening because data is being over-written.
Consider the following code:
a = [1 4 -2];
strColors = {'-r', '-g', '-b'};
% Pre allocating a matrix of size 3x25
funcOut = zeros(3,25);
for k=1:length(a)
LabFc3 = @(x)sin((a(k)/2)*pi*x).*(a(k)*x.^2+3);
fplot(LabFc3,[-8 8],strColors{k});
funcOut(k,:) = LabFc3(a(k)); linspace(-8,randi([0,8],1,1),25);
hold on;
end

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by