I keep getting an error message in my code
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 21 de Feb. de 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 comentarios
Gabriel
el 23 de Feb. de 2025
Walter Roberson
el 24 de Feb. de 2025
Editada: Walter Roberson
el 24 de Feb. de 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
el 25 de Feb. de 2025
Walter Roberson
el 25 de Feb. de 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
el 10 de Mzo. de 2025
Categorías
Más información sobre Graphics Performance 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!