error Unrecognized function or variable help me please :(!
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (3 件)
Catalytic
2024 年 2 月 10 日
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
0 件のコメント
Matt J
2024 年 2 月 10 日
編集済み: Matt J
2024 年 2 月 10 日
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
0 件のコメント
Stephen23
2024 年 2 月 10 日
編集済み: Stephen23
2024 年 2 月 10 日
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 件のコメント
Voss
2024 年 2 月 13 日
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!