Plot Multiple Time Series Based on Individual Condition
显示 更早的评论
Hello Friends!
I am somewhat new to scientific charting) more accustomed to working in Excel, but I think I have run into its limitation as regards to charting…I am not sure if Matlab can do the following…
1) Take the time series data from excel, each data series will have three describers (first three rows of each column) – COLOUR, TYPE and THICKNESS 2) plots each time series data in such a way as: a) colors the time series according to a time series criterion (eg. 1 for red, 2 for black) b) allows to adjust the thinness of the plotted series based on another criterion (e.g. 10 very thick, 2- close to hairline) c)Sets the type of the trendline to dashed/solid (based on the Type criterion)
I can send an example worksheet if necessary..
Thanks for your time!) I will be glad to hear any opinion.
Dima
采纳的回答
更多回答(2 个)
Fangjun Jiang
2011-9-14
Yes, all is pretty straightforward in MATLAB. You can type help plot or doc plot in MATLAB for more information. Try this example for yourself.
figure;hold on
plot(1:10,'r','linewidth',10)
plot(rand(10,1),'g--')
Code below applies to a simple example Excel file.
[Num,Txt,Raw]=xlsread('test.xls');
colors = {'r', 'k', 'g'}; %red, black, green
linetypes = {'--', '-'}; %dashed, solid
figure(1);hold on;
for k=2:4
plot(Num(4:end,1),Num(4:end,k),[colors{Num(1,k)},linetypes{Num(2,k)}],'linewidth',Num(3,k));
end
25 个评论
Dima
2011-9-14
Dima
2011-9-15
Fangjun Jiang
2011-9-15
I copied the below data to an Excel file called test.xls, note each data should be in a cell so the data will occupy from A1 to E12. Use the code in my answer to plot it.
1 1 2 3 COLOUR
1 2 1 2 TYPE
1 2 6 9 THICKNESS
1 1.040236104 1.038653607 0 0
2 1.039803766 1.038216885 0 0
3 1.039371429 1.037780164 0 0
4 1.038939091 1.037343443 0 0
5 1.038506753 1.036906721 0 0
6 1.038074416 1.03647 0 0
7 1.037642078 1.036033279 1.0624 0
8 1.03720974 1.035596557 1.061273448 0
9 1.036777403 1.035159836 1.060146897 0
Dima
2011-9-15
Dima
2011-9-15
Fangjun Jiang
2011-9-16
Do you have MS Excel on your computer? Is your computer a PC or Mac? The error message is about xlsread() function. Type doc xlsread to find out more.
Dima
2011-9-16
Dima
2011-9-16
Fangjun Jiang
2011-9-16
That site requires registration or extra tickets. I won't do it. You can construct the Excel file according to my previous comment. Just put every space-delimited item in a separate cell so you get every cell filled from A1 to E12. Then the code should run without any problem.
Fangjun Jiang
2011-9-16
Regarding the Excel error, refer to this post but I don't expect your Excel 2003 on Vista has that problem.
http://www.mathworks.com/matlabcentral/answers/14817-reading-excel-files-on-a-mac
Dima
2011-9-16
Dima
2011-9-16
Fangjun Jiang
2011-9-16
I think you've opened the door. You can type in help plot or doc plot in MATLAB Command Window to see how to change the color, marker and line style. In terms of x axis, plot(x,y) will use whatever data you have in the variable x.
Dima
2011-9-16
Dima
2011-9-16
Fangjun Jiang
2011-9-16
The "for k=2:4" statement means to plot the data from 2nd to 4th columnn, if you change it to "2:5", you need to have data in the 5th column.
Go through the "Gettting Started" portion of the MATLAB document, you'll learn lots of the basics.
Dima
2011-9-16
Fangjun Jiang
2011-9-16
I added a column and didn't have any error. You need to learn how to debug your code. Save the code in a script. Put a breakpoint and run the script one line at a time to see where is the problem.
Dima
2011-9-17
Fangjun Jiang
2011-9-17
In the code, linetypes = {'--', '-'}, means two options. In your Excel file, you have line style valued at 3, that's the problem. Did you mix color and line style?
Dima
2011-9-17
Fangjun Jiang
2011-9-17
Glad you like MATLAB programming. Reading that book is a really good start. If you have specific questions, this forum offers lots of help.
Dima
2011-9-17
Fangjun Jiang
2011-9-17
The function is text().
Dima
2011-9-18
Dima
2011-9-28
0 个投票
1 个评论
Walter Roberson
2011-9-28
[Num,Txt,Raw]=xlsread('test.xls');
colors = {'r', 'k', [0.6 0.8 3.9]}; %red, black, green
linetypes = {'--', '-'}; %dashed, solid
figure(1);hold on;
for k=2:4
plot(Num(4:end,1),Num(4:end,k),linetypes{Num(2,k)},'linewidth',Num(3,k), 'color', colors{k} );
end
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!