Matlab issues with plotting a variable

2 visualizaciones (últimos 30 días)
Joseph Chudnovsky
Joseph Chudnovsky el 17 de Mayo de 2021
Comentada: Star Strider el 17 de Mayo de 2021
Hello,
I have a csv file that I would like to take 2 columns from and make them x and y axis. I managed to plot one of the columns however the other column always gives me an error whenever I try to plot with it. I attached the data file below. Here is my code:
intel_cpus=readtable('intel.csv');
C=intel_cpus.("Cores");
E = intel_cpus.("BaseSpeed");
plot(C,'.')
I am trying to get columns D and F as axis of my graph. Thank you for any help!
  1 comentario
Mathieu NOE
Mathieu NOE el 17 de Mayo de 2021
hello
I noticed that the csv file as not same number of separators in all lines (separator = comma)
see the result in the table will right shift some fields
this is also obvious when you convert inot xlsx file with comma separator
need some cleaning first ...

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 17 de Mayo de 2021
There are gaps in the ‘Base Speed’ variable, so these need to be detected and the corresponding rows of ‘Cores’ eliminated in order for the vectors to have the same number of elements, as required by plot.
intel_cpus = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/620443/intel%20(2).csv','VariableNamingRule','preserve')
intel_cpus = 1619×7 table
Processor Status Release Date Cores Max Turbo Speed Base Speed Cache Size __________________________________________________ ________________ ____________ _____ _______________ ____________ ____________ {'Intel Core i9-9980XE Extreme Edition Processor'} {'Launched' } {'Q4'18'} 18 {'4.40 GHz'} {'3.00 GHz'} {'24.75 MB'} {'Intel Core i9-9960X X-series Processor' } {'Launched' } {'Q4'18'} 16 {'4.40 GHz'} {'3.10 GHz'} {'22 MB' } {'Intel Core i9-9940X X-series Processor' } {'Launched' } {'Q4'18'} 14 {'4.40 GHz'} {'3.30 GHz'} {'19.25 MB'} {'Intel Core i9-9920X X-series Processor' } {'Launched' } {'Q4'18'} 12 {'4.40 GHz'} {'3.50 GHz'} {'19.25 MB'} {'Intel Core i9-9900X X-series Processor' } {'Launched' } {'Q4'18'} 10 {'4.40 GHz'} {'3.50 GHz'} {'19.25 MB'} {'Intel Core i9-9820X X-series Processor' } {'Launched' } {'Q4'18'} 10 {'4.10 GHz'} {'3.30 GHz'} {'16.5 MB' } {'Intel Core i7-9800X X-series Processor' } {'Launched' } {'Q4'18'} 8 {'4.40 GHz'} {'3.80 GHz'} {'16.5 MB' } {'Intel Core i9-7980XE Extreme Edition Processor'} {'Launched' } {'Q3'17'} 18 {'4.20 GHz'} {'2.60 GHz'} {'24.75 MB'} {'Intel Core i9-7960X X-series Processor' } {'Launched' } {'Q3'17'} 16 {'4.20 GHz'} {'2.80 GHz'} {'22 MB' } {'Intel Core i9-7940X X-series Processor' } {'Launched' } {'Q3'17'} 14 {'4.30 GHz'} {'3.10 GHz'} {'19.25 MB'} {'Intel Core i9-7920X X-series Processor' } {'Launched' } {'Q3'17'} 12 {'4.30 GHz'} {'2.90 GHz'} {'16.5 MB' } {'Intel Core i9-7900X X-series Processor' } {'Launched' } {'Q2'17'} 10 {'4.30 GHz'} {'3.30 GHz'} {'13.75 MB'} {'Intel Core i7-7820X X-series Processor' } {'Launched' } {'Q2'17'} 8 {'4.30 GHz'} {'3.60 GHz'} {'11 MB' } {'Intel Core i7-7800X X-series Processor' } {'Launched' } {'Q2'17'} 6 {'4.00 GHz'} {'3.50 GHz'} {'8.25 MB' } {'Intel Core i7-7740X X-series Processor' } {'Discontinued'} {'Q2'17'} 4 {'4.50 GHz'} {'4.30 GHz'} {'8 MB' } {'Intel Core i5-7640X X-series Processor' } {'Discontinued'} {'Q2'17'} 4 {'4.20 GHz'} {'4.00 GHz'} {'6 MB' }
% Q2 = intel_cpus(178:198,:)
C = intel_cpus.('Cores');
E = intel_cpus.('Base Speed');
Lc = cellfun(@(x)~isempty(x), E, 'Unif',0); % Cell Array Of Logical Values
Lv = [Lc{:}]'; % Logical Vector
En = regexp(E,'\d+.\d+','match'); % Get Numeric Data
En = str2double([En{:}]).'; % Extract Numeric Data
figure
plot(C(Lv),En,'.')
grid
xlabel('Cores')
ylabel('Base Speed')
.
  7 comentarios
Joseph Chudnovsky
Joseph Chudnovsky el 17 de Mayo de 2021
what would the A and the C stand for?
Star Strider
Star Strider el 17 de Mayo de 2021
The easiest way to do that would be to use regexp to isolate the core designations, then use some sort of logical comparison or findgroups to get the cores you want, for example —
intel_cpus = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/620443/intel%20(2).csv','VariableNamingRule','preserve')
intel_cpus = 1619×7 table
Processor Status Release Date Cores Max Turbo Speed Base Speed Cache Size __________________________________________________ ________________ ____________ _____ _______________ ____________ ____________ {'Intel Core i9-9980XE Extreme Edition Processor'} {'Launched' } {'Q4'18'} 18 {'4.40 GHz'} {'3.00 GHz'} {'24.75 MB'} {'Intel Core i9-9960X X-series Processor' } {'Launched' } {'Q4'18'} 16 {'4.40 GHz'} {'3.10 GHz'} {'22 MB' } {'Intel Core i9-9940X X-series Processor' } {'Launched' } {'Q4'18'} 14 {'4.40 GHz'} {'3.30 GHz'} {'19.25 MB'} {'Intel Core i9-9920X X-series Processor' } {'Launched' } {'Q4'18'} 12 {'4.40 GHz'} {'3.50 GHz'} {'19.25 MB'} {'Intel Core i9-9900X X-series Processor' } {'Launched' } {'Q4'18'} 10 {'4.40 GHz'} {'3.50 GHz'} {'19.25 MB'} {'Intel Core i9-9820X X-series Processor' } {'Launched' } {'Q4'18'} 10 {'4.10 GHz'} {'3.30 GHz'} {'16.5 MB' } {'Intel Core i7-9800X X-series Processor' } {'Launched' } {'Q4'18'} 8 {'4.40 GHz'} {'3.80 GHz'} {'16.5 MB' } {'Intel Core i9-7980XE Extreme Edition Processor'} {'Launched' } {'Q3'17'} 18 {'4.20 GHz'} {'2.60 GHz'} {'24.75 MB'} {'Intel Core i9-7960X X-series Processor' } {'Launched' } {'Q3'17'} 16 {'4.20 GHz'} {'2.80 GHz'} {'22 MB' } {'Intel Core i9-7940X X-series Processor' } {'Launched' } {'Q3'17'} 14 {'4.30 GHz'} {'3.10 GHz'} {'19.25 MB'} {'Intel Core i9-7920X X-series Processor' } {'Launched' } {'Q3'17'} 12 {'4.30 GHz'} {'2.90 GHz'} {'16.5 MB' } {'Intel Core i9-7900X X-series Processor' } {'Launched' } {'Q2'17'} 10 {'4.30 GHz'} {'3.30 GHz'} {'13.75 MB'} {'Intel Core i7-7820X X-series Processor' } {'Launched' } {'Q2'17'} 8 {'4.30 GHz'} {'3.60 GHz'} {'11 MB' } {'Intel Core i7-7800X X-series Processor' } {'Launched' } {'Q2'17'} 6 {'4.00 GHz'} {'3.50 GHz'} {'8.25 MB' } {'Intel Core i7-7740X X-series Processor' } {'Discontinued'} {'Q2'17'} 4 {'4.50 GHz'} {'4.30 GHz'} {'8 MB' } {'Intel Core i5-7640X X-series Processor' } {'Discontinued'} {'Q2'17'} 4 {'4.20 GHz'} {'4.00 GHz'} {'6 MB' }
% Q2 = intel_cpus(178:198,:)
Pc = regexp(intel_cpus.Processor, 'i\d', 'match');
Pn = [Pc{:}]'
Pn = 642×1 cell array
{'i9'} {'i9'} {'i9'} {'i9'} {'i9'} {'i9'} {'i7'} {'i9'} {'i9'} {'i9'} {'i9'} {'i9'} {'i7'} {'i7'} {'i7'} {'i5'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'} {'i7'}
idx_i9 = ismember(Pn, 'i9')
idx_i9 = 642×1 logical array
1 1 1 1 1 1 0 1 1 1
% C = intel_cpus.('Cores');
% E = intel_cpus.('Base Speed');
% Lc = cellfun(@(x)~isempty(x), E, 'Unif',0); % Cell Array Of Logical Values
% Lv = [Lc{:}]'; % Logical Vector
%
% En = regexp(E,'\d+.\d+','match'); % Get Numeric Data
% En = str2double([En{:}]).'; % Extract Numeric Data
%
% figure
% plot(C(Lv),En,'.')
% grid
% xlabel('Cores')
% ylabel('Base Speed')
Then use that logical vector (‘idx_i9’ here) similarly to the way I used ‘Lv’ in the plot call, to define the rows of interest. Note that this would likely require combining logical vectors using the and,& function in order that the selected rows or vectors reflect both conditions (and any other logical conditions that might arise from further processing).
.

Iniciar sesión para comentar.

Más respuestas (1)

Markus
Markus el 17 de Mayo de 2021
Editada: Markus el 17 de Mayo de 2021
I think you want to remove the characters after the floating values. You cannot plot the values with the units attached.
While it might not be the cleanest, you could just go for:
D = str2double(replace(intel_cpus.("MaxTurboSpeed"),{' GHz',' MHz'},''));
and
E = str2double(replace(intel_cpus.("BaseSpeed"),{' GHz',' MHz'},''));
F = str2double(replace(intel_cpus.("CacheSize"),{' MB'},''));
Please do remember to add some code to keep the unit info regarding giga and mega.
I assume you are using this for something like an overview, so it should be fine.

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by