필터 지우기
필터 지우기

Selective plotting from .csv file

조회 수: 2 (최근 30일)
Ian
Ian 2014년 8월 12일
댓글: Michael Haderlein 2014년 9월 1일
Hi,
I've 2 sets of results from another software. Say Design1 and Design2. In each Design I've a set of X and Y values to plot. For Design1 the length is 1mm and for design2 the length is 2mm. So now, is it possible, If I type in 1mm it has to select design1 and plot the values under it. I've more than 200 Design results with x and y values under each. So I need to write a program so that If i type in a value, it'll select which design it is and plot the value.
Could someone pls help a little.

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 8월 12일
Will the design number always be equal to the length? Or might Design163 correspond to a length of 250 mm?
If the numbers are always the same, you can simply open the file by
n=7;
XY=dlmread(sprintf('%s\\Design%d.txt',currentpath,n));
Alternatively, you can of course also ask for the number with the inputdlg.
If the design number doesn't directly link to the length, you need to store the correlation additionally. Say, Design1-4 link to 1,2,5,10 mm, the correlation would be
c=[1 52 5 10];
l=5; %length in mm
n=find(c==l);
then read as shown above.
Plotting of course by
plot(XY(:,1),XY(:,2))

추가 답변 (2개)

Ian
Ian 2014년 8월 12일
Hi Michael,
No the design number is not equal to the length. Actually there are more parameters (around 20) to select each design, for eg: length= 5mm , width= 7mm, thickness = 2mm...etc. So If I type in these values for 20 parameters, It has to choose which design and plot. If I need to store each corelation separately, it would be like 200 Designs and 20 parametes each, almost 4000 corelations.
Should I write each correlation manually?
  댓글 수: 8
Michael Haderlein
Michael Haderlein 2014년 8월 16일
Ok, in this case you can use the following code:
fid=fopen('example.csv');
firstline=fgetl(fid);
ncolumns=1+sum(firstline==',');
ndesigns=length(regexp(firstline,'[^,]*'));
nparams=ncolumns-3*ndesigns-1;
data=textscan(fid,[repmat('%s%s%*s',1,ndesigns) '%*s' repmat('%s',1,nparams)],'delimiter',',','collectoutput',1);
fclose(fid);
values=str2double(reshape(data{1}(2:end,1:2*ndesigns),size(data{1},1)-1,2,ndesigns));
parameters=str2double(data{1}(2:ndesigns+1,2*ndesigns+1:end));
inputparams=str2double(inputdlg({'Length';'Width';'Thickness';'Temperature';'x';'y';'z'}))';
design=find(all(bsxfun(@eq,parameters,inputparams),2));
outputdata=values(:,:,design);
plot(outputdata(:,1),outputdata(:,2))
I hope this will also work with your larger file.
Ian
Ian 2014년 8월 19일
Hi Michael, Thank you very much. It works super fine. Thanks a lot.

댓글을 달려면 로그인하십시오.


Ian
Ian 2014년 8월 29일
Hi Michael, Thanks again for the code. Is it possible to use this code in the form of a GUI. I made a small gui using GUIDE, but not sure how to include this in it.
  댓글 수: 3
Ian
Ian 2014년 8월 29일
Hi Michael, Should i change this in the GUI code or the code you sent. If I change it in your code, It shows the following error,
Undefined variable "handles" or function "handles.uipanel1".
Error in Interface1 (line 14)
hedit=get(handles.uipanel1,'Int1');
Michael Haderlein
Michael Haderlein 2014년 9월 1일
Just in your GUIDE m code. You have the line where you define inputparams=... in the puhsbutton1_Callback. Replace this line by the ones I have posted.

댓글을 달려면 로그인하십시오.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by