I keep getting an error message in my code
Show older comments
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
Answers (1)
Walter Roberson
on 21 Feb 2025
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 Comments
Gabriel
on 23 Feb 2025
Walter Roberson
on 24 Feb 2025
Edited: Walter Roberson
on 24 Feb 2025
Well, there are a few possibilities:
- t might be a character vector or string() object, and plot() is trying to interpret it as an option
- data_na(i,:) might be a character vector or a string() object, and plot() is trying to interpret it as a line specification.
- col(:,i) or col(i,:) might not be either numeric or a character vector or a string() object
- col(:,i) or col(i,:) might not be either scalar or of length 3 or length 4
- You might have a third-party plot.m in your MATLAB path that is interfering with calling the built-in plot() function
Gabriel
on 25 Feb 2025
Walter Roberson
on 25 Feb 2025
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
on 10 Mar 2025
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!