Selective plotting from .csv file
이전 댓글 표시
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.
채택된 답변
추가 답변 (2개)
Ian
2014년 8월 12일
0 개 추천
댓글 수: 8
Michael Haderlein
2014년 8월 12일
Where is the correlation stored? In the Design files? Or how do you know it?
Michael Haderlein
2014년 8월 12일
I don't quite understand the matter now. So the content of your file is
Design 1,,,Design 2,,,,,,,,,,
Moment,Angle,,Moment,Angle,,Parameters,Length,Width,Thickness,temperature,x,y,z
0.05,2,,0.5,10,,Design1,5,21.8,8,50.87,0.45,0.0028,0.2
0.09,5,,0.55,16,,Design2,8.2,10,2,21.65,0.015,0.012,0.1
0.12,9,,0.61,24,,,,,,,,,
0.18,15,,1.25,29,,,,,,,,,
0.4,23,,2.2,35,,,,,,,,,
0.57,30,,3,41,,,,,,,,,
0.71,42,,3.4,50,,,,,,,,,
0.76,51,,4.2,57,,,,,,,,,
0.82,62,,5.7,61,,,,,,,,,
0.95,70,,6.5,68,,,,,,,,,
Now if you type in "5,21.8,8,50.87,0.45,0.0028,0.2" (7 parameters) you want to have Design1, if you instead type in "8.2,10,2,21.65,0.015,0.012,0.1", you want to have Design2? In case you decide for Design1, is the data you want to plot the entire first column (0.05-0.95) vs. the second column (2-70)?
Are all designs saved in one file or are there more files with the other 198 designs?
Ian
2014년 8월 12일
Michael Haderlein
2014년 8월 13일
Ok, but then the format is really strange. Just to be sure, the first two lines which have numbers (so lines 3/4) have both the design definition AND x/y data stored?
Ian
2014년 8월 13일
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
2014년 8월 19일
Ian
2014년 8월 29일
0 개 추천
댓글 수: 3
Michael Haderlein
2014년 8월 29일
Ok, my problem is that I never use GUIDE, so my answer might be odd for someone who is used to GUIDE (in case I want a GUI, I do it by hand). However, what you can do is
hedit=get(handles.uipanel1,'children');
inputparams=str2double(get(hedit([7,4,1,8,6,5,3]),'string'))';
The reordering of the objects ([7,4,...]) is necessary as the order of the objects is different from what it's supposed to be. Also, there's no box property, so I just left it. Anyway, if you replace the inputparams=... line by the two lines above, it should work.
Ian
2014년 8월 29일
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.
카테고리
도움말 센터 및 File Exchange에서 Statistics and Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!