필터 지우기
필터 지우기

Matlab issues with plotting a variable

조회 수: 1 (최근 30일)
Joseph Chudnovsky
Joseph Chudnovsky 2021년 5월 17일
댓글: Star Strider 2021년 5월 17일
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일
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
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일
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.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by