I keep getting an error message in my code

조회 수: 3 (최근 30일)
Gabriel
Gabriel 2025년 2월 21일
댓글: Gabriel 2025년 3월 10일
I keep getting error message. I started out the code with the 2 lines below:
13 addpath(strcat(pwd,'\functions\')) % add path where you saved to memd function
14 save_path = strcat(pwd,'\figs\'); % path where you want to save your figures
And I keep getting the message:
Warning: Name is nonexistent or not a directory: C:\Users\Name\Downloads\functions
> In path (line 109) (line 109 is a blank in the code)
>In addpath (line 86)
In MyVersiontestcode (line 13)
noise = 0×15000 empty double matrix
Error using plot
Invalid color or line style.
Error in MyVersiontestcode (line 86)
86 plot(t,data_na(i,:),'color',col(:,i),'LineWidth',2);
-------------------------------------
Does somebody have a suggestion as to what the problem might be?
Thank you
Gabe

답변 (1개)

Walter Roberson
Walter Roberson 2025년 2월 21일
plot(t,data_na(i,:),'color',col(:,i),'LineWidth',2);
My guess is that you need
plot(t,data_na(i,:),'color',col(i,:),'LineWidth',2);
  댓글 수: 5
Walter Roberson
Walter Roberson 2025년 2월 25일
There is no way to plot using character vectors as coordinates.
One possibility is
plot(t,double(data_na(i,:)),'color',col(i,:),'LineWidth',2);
XT = xticks;
xlabel(cellstr(char(XT(:))))
This will treat the character entries in data_na as a vector of offsets, draw using those coordinates, and then relabel the tick positions back to the character versions. For example if data_na(i,:) were 'DEAD' then it would treat it as double(['D', 'E', 'A', 'D']) which is [68 69 65 68] and would draw using those as coordinates.
I have to wonder, however, whetherr data_na(i,:) represents categorical data? If so then something more like
plot(t, categorical(cellstr(data_na)))
would be expected, treating each row of data_na as a categorical entry.
Maybe what is going on should be converted to
pointsize = 16;
scatter(t, categorical(cellstr(data_na)), pointsize, col)
with no loop.
Gabriel
Gabriel 2025년 3월 10일
Thank you. I'll change the code and see =how it works.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by