Plotting from Cell Array/Matrix/Database

1 回表示 (過去 30 日間)
Andrei Hirtie
Andrei Hirtie 2017 年 1 月 2 日
コメント済み: Andrei Hirtie 2017 年 1 月 3 日
Hey guys.
I`m looking for some help regarding ploting data extracted from SQL Databases.
I have made a simple SQL script where I query particular databases for data of interest. The return data type from the sql query is cell array, reason being that I do not have only numeric data. I might have numbers / characters combinations or just characters on some columns. My interest is to see a distribution pattern in my dataset and I want to plot that. For example I have a number of suppliers some of which are from UK, US, Canada etc. Then I want to plot this distribution accordingly but because my data is not numeric I cannot find anyway to do this.
To be more precise - I am trying to - on the y axis have the number (3,4,10 etc) and on the x axis the distribution pattern like UK, US etc.
My few lines of code are:
%
clc
clear
setdbprefs('FetchInBatches', 'yes')
setdbprefs('FetchBatchSize', '2')
setdbprefs('DataReturnFormat', 'cellarray');
connection = database('DB64bit', '', '');
results = runsqlscript(connection, 'MySqlScript.sql');
data1 = results(1).Data;
figure
plot(data1)
There is sort of a perfect example from MatLab where it does something similar with a "hospital" example, but the data is not imported from sqldb. In that example they observe distributions among patients which is exactly what I am trying to do.
Thank in advance.

回答 (1 件)

Damjan Lasic
Damjan Lasic 2017 年 1 月 3 日
This is difficult to answer without a clear example of your cell data.
I presume you have a cell which contains strings, and numbers associated with these strings, and you want to plot a histogram (<http://www.mathworks.com/help/matlab/ref/histogram.html> -> see histogram with properties). In the documentaion it should be clear how to do it when you have transformed your data to required form.
On the latter, you can extract cell contents using curly braces. For example:
%make a cell array with mixed contents
cell_1 = {1,'aa',3}
%using normal braces returns a cell
cell_1(1)
%using curly bracers returns the "content" of the cell
cell_1{1}
If you are still unclear about how to manipulate data types in your case, you can post an example of your cell so i can improve my answer.
Kind regards, Damjan
  1 件のコメント
Andrei Hirtie
Andrei Hirtie 2017 年 1 月 3 日
Thanks for your answer Damjan. I actually think this might work. Let me try and get back to you.

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

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by