error Unrecognized function or variable help me please :(!
Mostrar comentarios más antiguos
the question(the part i tried to solve):
Write a function called PlotSignal, the function will display on a graph the signal it receives.
1.1. The function inputs are:
1.1.1 signalsCell – an object of cell array type, (each pair of rows in it represents one letter, see details
At the end of the question(
1.1.2 n – the number of the signal to be displayed
1.2. The function does not return any value.
1.3. The letter n from the array of cells should be displayed on a graph according to the following detail:
1.3.1. The signal color shall be black.
as you see i have an error in my code i dont know how to load the input in the workspace i tried to do
function PlotSignal(signalsCell, n)
signalsCell=signals(2*n-1:2*n,:);
Y=cell2mat(signalsCell);
X=signals(n,:);
figure;
plot(X,Y,'k');
end
the eroor
Unrecognized function or variable 'signalsCell'.
can someone please help me ? even to write all over again the function please?
thanks !
11 comentarios
Stephen23
el 9 de Feb. de 2024
How are you calling the function?
My guess is that you are calling it something like this:
PlotSignal(signalsCell, n)
In which case... what value/s do you expect signalsCell to have?
Please show us exactly how you define its input arrays, and exactly how you call this function.
Torsten
el 9 de Feb. de 2024
function PlotSignal(signalsCell, n)
signalsCell=signals(2*n-1:2*n,:);
"signalsCell" is the input to your function "PlotSignal" and you overwrite it by "signals(2*n-1:2*n,:)". This must be wrong.
Time
el 10 de Feb. de 2024
Stephen23
el 10 de Feb. de 2024
"And what do you mean by overwrite ? How do I fix it ?"
What you are doing, overwriting the input argument SIAGNALSCELL and not definiing SIGNALS anywhere:
function PlotSignal(signalsCell, n)
signalsCell=signals(2*n-1:2*n,:);
What you probably intended to do:
function PlotSignal(signals,n)
signalsCell = signals(2*n-1:2*n,:);
Time
el 10 de Feb. de 2024
Stephen23
el 10 de Feb. de 2024
"But in the question they tell me the input need to be "signalscell" ."
Sure, is there something stopping you from changing the variable names youself?
Time
el 10 de Feb. de 2024
tal
el 10 de Feb. de 2024
here:)
Stephen23
el 10 de Feb. de 2024
And also show us how you call the function.
tal
el 10 de Feb. de 2024
n=3;
load('signals.mat','signals')
PlotSignal(signals,n);
Respuestas (3)
signalsCell=load('signals').signals;
PlotSignal(signalsCell, 3)
function PlotSignal(signalsCell, n)
Headings=signalsCell(:,1);
Table=cell2table(signalsCell(:,2:end)');
plot(Table, 2*n-1,2*n,Color='k');
xlabel(Headings{2*n-1});
ylabel(Headings{2*n});
end
Perhaps as follows?
signalsCell=load('signals').signals;
PlotSignal(signalsCell, 3)
function PlotSignal(signalsCell, n)
signalsCell=num2cell(cell2mat(signalsCell(:,2:end)),2);
X=signalsCell(1:2:end);
Y=signalsCell(2:2:end);
figure;
plot(X{n},Y{n},'o-k');
end
That really is very bad data design: one single numeric array would be much better than storing lots of numeric scalars in a huge cell array. Your tutor tried to replicate something like a TABLE... but should just use a TABLE. You will have to unlearn half of what they show you :(
signals = load('signals.mat').signals
PlotSignal(signals,1)
PlotSignal(signals,3)
function PlotSignal(inp,n)
sig = "y"+n;
idx = find(strcmpi(sig,inp(:,1)));
X = cell2mat(inp(idx-1,2:end));
Y = cell2mat(inp(idx-0,2:end));
plot(X,Y,'+-k');
legend(sig)
end
11 comentarios
tal
el 10 de Feb. de 2024
thank you so much for your help ! i really appriciate it . do the way i wrote the function it isnt corect at all ?
"do the way i wrote the function it isnt corect at all ?"
It works when you fix the bugs and call it correctly. For example:
signals = load('signals.mat').signals;
PlotSignal(signals,3)
function PlotSignal(signalsCell, n)
X = cell2mat(signalsCell(2*n-1,2:end));
Y = cell2mat(signalsCell(2*n-0,2:end));
plot(X,Y,'k');
end
Time
el 13 de Feb. de 2024
Walter Roberson
el 13 de Feb. de 2024
You would get an error in the second line if you pressed the green Run button to execute the code. When you press the green Run button to execute the code, it executes the function with no input parameters.
You need to go down to the command line and
signals = load('signals.mat').signals;
PlotSignal(signals,3)
Time
el 13 de Feb. de 2024
Editada: Walter Roberson
el 13 de Feb. de 2024
Walter Roberson
el 13 de Feb. de 2024
What is the error message?
Time
el 13 de Feb. de 2024
Walter Roberson
el 13 de Feb. de 2024
As a test, add a whos command near the top,
function PlotSignal(signalsCell, n)
whos
X=signalsCell(2*n-1,2*n);
Y = cell2mat(signalsCell(2:end));
figure;
plot(X,Y,'k');
end
and see what the result is
Time
el 13 de Feb. de 2024
@Time: However, if I modify the function as suggested by Stephen, it runs fine:
n=3;
load('signals.mat','signals')
PlotSignal(signals,n);
function PlotSignal(signalsCell, n)
X = cell2mat(signalsCell(2*n-1,2:end));
Y = cell2mat(signalsCell(2*n-0,2:end));
plot(X,Y,'k');
end
Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





