error Unrecognized function or variable help me please :(!

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 件のコメント

Stephen23
Stephen23 2024 年 2 月 9 日
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
Torsten 2024 年 2 月 9 日
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
Time 2024 年 2 月 10 日
Every signal represent two rows from the array( sign in red ) And what do you mean by overwrite ? How do I fix it ?
Stephen23
Stephen23 2024 年 2 月 10 日
"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
Time 2024 年 2 月 10 日
But in the question they tell me the input need to be "signalscell" .
Stephen23
Stephen23 2024 年 2 月 10 日
"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
Time 2024 年 2 月 10 日
yes .. but anyway i tried the way you wrote me and it still dosent work.
thr same error
Stephen23
Stephen23 2024 年 2 月 10 日
"but anyway i tried the way you wrote me and it still dosent work. thr same error"
Sure. Did you read here and provide us with the requested information? Not yet.
tal
tal 2024 年 2 月 10 日
here:)
Stephen23
Stephen23 2024 年 2 月 10 日
And also show us how you call the function.
tal
tal 2024 年 2 月 10 日
n=3;
load('signals.mat','signals')
PlotSignal(signals,n);

サインインしてコメントする。

回答 (3 件)

Catalytic
Catalytic 2024 年 2 月 10 日

1 投票

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
Matt J
Matt J 2024 年 2 月 10 日
編集済み: Matt J 2024 年 2 月 10 日

0 投票

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
Stephen23
Stephen23 2024 年 2 月 10 日
編集済み: Stephen23 2024 年 2 月 10 日

0 投票

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
signals = 6×56 cell array
Columns 1 through 13 {'time'} {[ 0]} {[ 0.1164]} {[ 0.2327]} {[ 0.3491]} {[ 0.4654]} {[ 0.5818]} {[ 0.6981]} {[ 0.8145]} {[ 0.9308]} {[ 1.0472]} {[ 1.1636]} {[ 1.2799]} {'y1' } {[ 7]} {[ 7.5805]} {[ 8.1531]} {[ 8.7101]} {[ 9.2440]} {[ 9.7475]} {[10.2139]} {[10.6369]} {[11.0106]} {[11.3301]} {[11.5911]} {[11.7899]} {'time'} {[-6.2832]} {[-6.0505]} {[-5.8178]} {[-5.5851]} {[-5.3523]} {[-5.1196]} {[-4.8869]} {[-4.6542]} {[-4.4215]} {[-4.1888]} {[-3.9561]} {[-3.7234]} {'y2' } {[ 4]} {[ 4.1153]} {[ 4.2244]} {[ 4.3214]} {[ 4.4011]} {[ 4.4591]} {[ 4.4924]} {[ 4.4992]} {[ 4.4790]} {[ 4.4330]} {[ 4.3637]} {[ 4.2748]} {'time'} {[-6.2832]} {[-6.1668]} {[-6.0505]} {[-5.9341]} {[-5.8178]} {[-5.7014]} {[-5.5851]} {[-5.4687]} {[-5.3523]} {[-5.2360]} {[-5.1196]} {[-5.0033]} {'y3' } {[50.1000]} {[49.7619]} {[48.7522]} {[47.0846]} {[44.7816]} {[41.8744]} {[38.4022]} {[34.4121]} {[29.9579]} {[25.1000]} {[19.9040]} {[14.4402]} Columns 14 through 25 {[ 1.3963]} {[ 1.5126]} {[ 1.6290]} {[ 1.7453]} {[ 1.8617]} {[ 1.9780]} {[ 2.0944]} {[ 2.2108]} {[ 2.3271]} {[ 2.4435]} {[ 2.5598]} {[ 2.6762]} {[11.9240]} {[11.9915]} {[11.9915]} {[11.9240]} {[ 11.7899]} {[ 11.5911]} {[ 11.3301]} {[ 11.0106]} {[ 10.6369]} {[ 10.2139]} {[ 9.7475]} {[ 9.2440]} {[-3.4907]} {[-3.2579]} {[-3.0252]} {[-2.7925]} {[ -2.5598]} {[ -2.3271]} {[ -2.0944]} {[ -1.8617]} {[ -1.6290]} {[ -1.3963]} {[ -1.1636]} {[ -0.9308]} {[ 4.1710]} {[ 4.0580]} {[ 3.9420]} {[ 3.8290]} {[ 3.7252]} {[ 3.6363]} {[ 3.5670]} {[ 3.5210]} {[ 3.5008]} {[ 3.5076]} {[ 3.5409]} {[ 3.5989]} {[-4.8869]} {[-4.7706]} {[-4.6542]} {[-4.5379]} {[ -4.4215]} {[ -4.3051]} {[ -4.1888]} {[ -4.0724]} {[ -3.9561]} {[ -3.8397]} {[ -3.7234]} {[ -3.6070]} {[ 8.7824]} {[ 3.0072]} {[-2.8072]} {[-8.5824]} {[-14.2402]} {[-19.7040]} {[-24.9000]} {[-29.7579]} {[-34.2121]} {[-38.2022]} {[-41.6744]} {[-44.5816]} Columns 26 through 37 {[ 2.7925]} {[ 2.9089]} {[ 3.0252]} {[ 3.1416]} {[ 3.2579]} {[ 3.3743]} {[ 3.4907]} {[ 3.6070]} {[ 3.7234]} {[ 3.8397]} {[ 3.9561]} {[ 4.0724]} {[ 8.7101]} {[ 8.1531]} {[ 7.5805]} {[ 7.0000]} {[ 6.4195]} {[ 5.8469]} {[ 5.2899]} {[ 4.7560]} {[ 4.2525]} {[ 3.7861]} {[ 3.3631]} {[ 2.9894]} {[ -0.6981]} {[ -0.4654]} {[ -0.2327]} {[ 0]} {[ 0.2327]} {[ 0.4654]} {[ 0.6981]} {[ 0.9308]} {[ 1.1636]} {[ 1.3963]} {[ 1.6290]} {[ 1.8617]} {[ 3.6786]} {[ 3.7756]} {[ 3.8847]} {[ 4]} {[ 4.1153]} {[ 4.2244]} {[ 4.3214]} {[ 4.4011]} {[ 4.4591]} {[ 4.4924]} {[ 4.4992]} {[ 4.4790]} {[ -3.4907]} {[ -3.3743]} {[ -3.2579]} {[ -3.1416]} {[ -3.0252]} {[ -2.9089]} {[ -2.7925]} {[ -2.6762]} {[ -2.5598]} {[ -2.4435]} {[ -2.3271]} {[ -2.2108]} {[-46.8846]} {[-48.5522]} {[-49.5619]} {[-49.9000]} {[-49.5619]} {[-48.5522]} {[-46.8846]} {[-44.5816]} {[-41.6744]} {[-38.2022]} {[-34.2121]} {[-29.7579]} Columns 38 through 50 {[ 4.1888]} {[ 4.3051]} {[ 4.4215]} {[ 4.5379]} {[ 4.6542]} {[ 4.7706]} {[ 4.8869]} {[ 5.0033]} {[ 5.1196]} {[ 5.2360]} {[ 5.3523]} {[ 5.4687]} {[ 5.5851]} {[ 2.6699]} {[ 2.4089]} {[ 2.2101]} {[ 2.0760]} {[ 2.0085]} {[ 2.0085]} {[ 2.0760]} {[ 2.2101]} {[ 2.4089]} {[ 2.6699]} {[ 2.9894]} {[ 3.3631]} {[ 3.7861]} {[ 2.0944]} {[ 2.3271]} {[ 2.5598]} {[ 2.7925]} {[ 3.0252]} {[ 3.2579]} {[ 3.4907]} {[ 3.7234]} {[ 3.9561]} {[ 4.1888]} {[ 4.4215]} {[ 4.6542]} {[ 4.8869]} {[ 4.4330]} {[ 4.3637]} {[ 4.2748]} {[ 4.1710]} {[ 4.0580]} {[ 3.9420]} {[ 3.8290]} {[ 3.7252]} {[ 3.6363]} {[ 3.5670]} {[ 3.5210]} {[ 3.5008]} {[ 3.5076]} {[ -2.0944]} {[ -1.9780]} {[ -1.8617]} {[-1.7453]} {[-1.6290]} {[-1.5126]} {[-1.3963]} {[-1.2799]} {[-1.1636]} {[-1.0472]} {[-0.9308]} {[-0.8145]} {[-0.6981]} {[-24.9000]} {[-19.7040]} {[-14.2402]} {[-8.5824]} {[-2.8072]} {[ 3.0072]} {[ 8.7824]} {[14.4402]} {[19.9040]} {[25.1000]} {[29.9579]} {[34.4121]} {[38.4022]} Columns 51 through 56 {[ 5.7014]} {[ 5.8178]} {[ 5.9341]} {[ 6.0505]} {[ 6.1668]} {[ 6.2832]} {[ 4.2525]} {[ 4.7560]} {[ 5.2899]} {[ 5.8469]} {[ 6.4195]} {[ 7.0000]} {[ 5.1196]} {[ 5.3523]} {[ 5.5851]} {[ 5.8178]} {[ 6.0505]} {[ 6.2832]} {[ 3.5409]} {[ 3.5989]} {[ 3.6786]} {[ 3.7756]} {[ 3.8847]} {[ 4]} {[-0.5818]} {[-0.4654]} {[-0.3491]} {[-0.2327]} {[-0.1164]} {[ 0]} {[41.8744]} {[44.7816]} {[47.0846]} {[48.7522]} {[49.7619]} {[50.1000]}
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 件のコメント

tal
tal 2024 年 2 月 10 日
thank you so much for your help ! i really appriciate it . do the way i wrote the function it isnt corect at all ?
Stephen23
Stephen23 2024 年 2 月 10 日
編集済み: Stephen23 2024 年 2 月 10 日
"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
Time 2024 年 2 月 13 日
i dont get it it dosent work with the script i sent here / and in the part of the practice i must use this script so how come it dosent work ?
and the huge problem i had is that i havents used the input i eneter in the function as the proffesor said ..
whats wrong with the code again ? i get an error in the second line ..
and can you please show me how you solve it with the script i sent here ?
function PlotSignal(signalsCell, n)
X=signalsCell(2*n-1,2*n);
Y = cell2mat(signalsCell(2:end));
figure;
plot(X,Y,'k');
end
Walter Roberson
Walter Roberson 2024 年 2 月 13 日
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
Time 2024 年 2 月 13 日
編集済み: Walter Roberson 2024 年 2 月 13 日
n=3;
load('signals.mat','signals')
PlotSignal(signals,n);
Why this command isn't ok?
Walter Roberson
Walter Roberson 2024 年 2 月 13 日
What is the error message?
Time
Time 2024 年 2 月 13 日
The same error I wrote in the begging itdosen recognize signalscelll
Walter Roberson
Walter Roberson 2024 年 2 月 13 日
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
Time 2024 年 2 月 13 日
Well I'll do it tomorrow morning I am not near the computer anymore . What does who's command does ? And did you try to run the function maybe on your own and know what is the problem ? Fyi I added here a fille of array .
Voss
Voss 2024 年 2 月 13 日
@Time: I get a different error (using the mat file provided by @tal):
n=3;
load('signals.mat','signals')
PlotSignal(signals,n);
Error using cell2mat
All contents of the input cell array must be of the same data type.

Error in solution>PlotSignal (line 7)
Y = cell2mat(signalsCell(2:end));
function PlotSignal(signalsCell, n)
X=signalsCell(2*n-1,2*n);
Y = cell2mat(signalsCell(2:end));
figure;
plot(X,Y,'k');
end
Voss
Voss 2024 年 2 月 13 日
編集済み: Voss 2024 年 2 月 13 日
@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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

質問済み:

2024 年 2 月 9 日

編集済み:

2024 年 2 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by