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 件のコメント

Mathieu NOE
Mathieu NOE 2021 年 5 月 17 日
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 ...

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2021 年 5 月 17 日

0 投票

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 件のコメント

Mathieu NOE
Mathieu NOE 2021 年 5 月 17 日
seems I am still too slow and too late ... huh
intel_cpus = readtable('intel.csv','TreatAsEmpty',{''});
C=intel_cpus.("Cores");
E = intel_cpus.("BaseSpeed");
Es = split(E,' ');
% values expressed in MHz must be converted in GHz to keep coherence
strs = Es(:,2);
ind=find(ismember(strs,'MHz'));
E_data = cellfun(@str2double,Es(:,1));
E_data(ind) = E_data(ind)/1000;
figure(1),scatter(C,E_data,50)
xlim([0 20]);
figure(2),bubblechart(C,E_data,1*ones(size(C)),'MarkerEdgeColor','k')
xlim([0 20]);
Joseph Chudnovsky
Joseph Chudnovsky 2021 年 5 月 17 日
Hey so I just tried the code and I am getting an error at the Es = split(E,' ');
Do you know what may be causing this?
Star Strider
Star Strider 2021 年 5 月 17 日
@Joseph Chudnovsky — Note that @Mathieu NOE should have posted that as a separate Answer, not as a Comment to my Answer, that works correctly and runs without error.
Joseph Chudnovsky
Joseph Chudnovsky 2021 年 5 月 17 日
Hello, I know I have been bothering you, but how would I maybe get specifc rows to plot. I have i9's for example save as an indice but how could I get the specifc "cores" for those i9's for example?
Markus
Markus 2021 年 5 月 17 日
You need to search for the rows that include 'i9' in the name column, check Mathieu's comment >>find(ismember(strs,'i9'))
you should be able to address the corresponding cells with something like
i9_cores=C(find(ismember(A,'i9')));
Joseph Chudnovsky
Joseph Chudnovsky 2021 年 5 月 17 日
what would the A and the C stand for?
Star Strider
Star Strider 2021 年 5 月 17 日
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).
.

サインインしてコメントする。

その他の回答 (1 件)

Markus
Markus 2021 年 5 月 17 日
編集済み: Markus 2021 年 5 月 17 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeLanguage Fundamentals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by