In my Sonoanalysis program, I need to mark the position I want on the sono image. Before I read this article: Superimposing line plots on image, there are two ways I thought to achieve this task. One is using plot function, and the other is changing the color of the pixel of position I click. However, the later method has a critical problem that it may be a time wasting method if I want to mark the position repeatedly, because I have to change several pixels if the shape of the marker is cross or circle. As a result of that, I choose the first way to accomplish my task finally. Today, I surfed on the internet to seek the correct method to do this kind of thing.
In this article: Superimposing line plots on image, the author who manages the Image & Geospatial development team at the Mathworks shows the way by using plot function, so I think it is a better way to do this task.
今天為了讓別台電腦也能夠跑Matlab程式,到處搜尋,最後在PTT Matlab版上找到了辦法:
如何將GUI轉成執行檔EXE,在未安裝MATLAB之電腦執行?
首先須先有以經做好的gui.m文件和gui.fig文件:
1.在matlab的command窗口中輸入 mcc -B sgl GUI.m
2.將上步生成的文件連同GUI.m文件和GUI.fig文件一起COPY到執行的電腦上(未安裝MATLAB的電腦),並放置在同一個資料夾下。
3.再去\toolbox\compiler\deploy\win32目錄下面找 MCRinstaller.exe 這個檔案(約102MB),複製到(別殺掉此檔!!)要執行的電腦上安裝。
4.安裝後即可編譯GUI.exe。^^
以上為最近使用心得.....提供給大家參考~~~祝大家玩個愉快....
前言:改良自碩士班的原始版本,當初懵懵懂懂寫得很亂,現在以新觀念方法改造。

- Load File:開啟後選取圖片資料夾,資料夾內圖片會以[sort_name] = sort_file(path)排列,目的是將連續圖片排序,若是一般則以sort的方式(排列字母大小等)。但是當初因為自己的失誤把檔名寫成1.jpg, 2.jpg ….. 10.jpg, 11.jpg…..,經過排列後會變成1.jpg, 10.jpg, 11.jpg, ……, 19.jpg, 2.jpg, 21.jpg…..,因此才多寫若是檔名不一樣長,則以不同cell的方式將相同長度檔名放入排列(目前只有到十位數)。
- Sliderbar:會將sort過得file按照順序排列,提供一張張點選。
- position select:則是以sono_mousedown.m方式,將滑鼠點所點的點的座標顯示。
- Dist tool:以matlab內建的dist tool作用,不過目前沒有校正顯示的長度。
- Save Figure & value:將座標值存入table中,並且將點選好的圖片存入目前資料夾內,並且以[path new_filename] = changefilename(filename,add_word)改名(如:a_原始檔名)。改名之後,由於儲存圖檔的時候當初以plot方式所畫得十字記號無法存入,因此以[change_image] = draw_image(im,x,y)方式,將所選取的座標位置上下左右15個像素統統改成紅色(即變成十字)。
匯入座標資料於table,並且[cal_dist]=calcu_dist(ini_p,cal_p,dist_prop),依目前深度計算和第一點的距離。 - Export:將資料匯出,內建以目前資料夾為匯出處,以[file,path]=uiputfile('.txt','Save file as',eval('[handles.path default_file]'))完成想要匯出的資料夾,預設以dist.txt作為預設匯出檔名。
匯出後以sonofilemerge(path,sonofile,distfile)自動和sono.txt檔案結合成stiff.txt(個人需要)。
這個東西我實在沒有時間好好的把他製作一番。
electroGUI V.0.0001(毫無意義版)界面介紹


若是資料選取順序錯誤,則會出現警告。

結論:
目前版本非常陽春而且bugs很多,待我有空有時間,在陸續修正並增加新功能,不過對於計算peak to peak amplitude目前來說應已經足夠。
electroGUI V.0.0001(毫無意義版)界面介紹

- 開啟(以autochoosetype.m):目前內建可讀全部為數據的txt檔(以textread開啟),InstruNet(以readintranet.m開啟)所產生的.TXT檔(如:Ch1_Vin+.TXT),以及一般具有標頭檔案(以hdrload.m開啟)。
- 資料數據(以datacursor):則是可以點選圖形,顯示原始x,y資料點,如下圖:

- 選取範圍(以get_x_point.m):即點選圖形區域,目前規定要由左到右選取。如下圖:點選後按peak to peak即以所填入的放大倍率計算peak to peak amplitude。

若是資料選取順序錯誤,則會出現警告。

結論:
目前版本非常陽春而且bugs很多,待我有空有時間,在陸續修正並增加新功能,不過對於計算peak to peak amplitude目前來說應已經足夠。
這個影片介紹了如何在GUIDE中,建立互相獨立的radio button,說真的,我是今天才找到這個資料,之前也是百思不得其解,好在youtube有人分享。
不過,因為這個不是英文也不是中文,所以應該聽不懂他在說啥,但是就算不聽看操作步驟也應該是可以懂得!
今天我有一個檔案長得如下:
在matlab裡面一定沒有辦法用既有的textread讀取,因為第一行的文字!於是我寫個個跳過第一行的程式!如下:
概念很簡單,就是輸入要跳過的行數,然後以行數來計算一行一行存成矩陣!但是這時候我又想到,剛好今天我這個檔案非常的小,行數也很短,如果我今天拿上萬行的數據執行,執行到死都執行不完!。
百思不得其解後,google了許久,在matlab官方網站看到了有人分享的寫法:
簡單的說,這個程式先一行一行判斷是否為string(if ~isstr(line)),然後在以data = [data; fscanf(fid, '%f')];讀入數值資料,並且會以[data, ncols, errmsg, nxtindex] = sscanf(line, '%f');(其中line是先讀入一行)去看ncols。
最後再把讀入的數值data資料用reshape的方式(data = reshape(data, ncols, length(data)/ncols);)完成。速率的確加快許多。
frame force angle
180.000000 25.907727 -96.707100
198.000000 52.657283 -97.686900
206.000000 79.306087 -97.134200
216.000000 105.920720 -96.028800
234.000000 132.531830 -95.501200
252.000000 159.259191 -95.023900
271.000000 185.936060 -94.496300
293.000000 212.583572 -94.194800
312.000000 239.251047 -92.586900
332.000000 265.956685 -91.506600
357.000000 292.655864 -91.556900
364.000000 265.886229 -91.255400
369.000000 239.255744 -91.582000
376.000000 212.594141 -92.813000
384.000000 185.939583 -92.586900
394.000000 159.297355 -93.215000
406.000000 132.574103 -93.390900
421.000000 105.981781 -93.943600
434.000000 79.340140 -94.747500
468.000000 52.674016 -96.104100
501.000000 25.987401 -97.360300
在matlab裡面一定沒有辦法用既有的textread讀取,因為第一行的文字!於是我寫個個跳過第一行的程式!如下:
function mat_a = get_to_mat(filename,l)
fp = fopen(filename);
current_l = 1;
while 1
content = fgetl(fp);
if current_l <= l
tile = content;
current_l = current_l +1;
elseif current_l > l & ischar(content) == 1
mat_a(current_l - l,:) = str2num(content);
current_l = current_l +1;
elseif ischar(content) == 0
break
end
end
fclose(fp);;
概念很簡單,就是輸入要跳過的行數,然後以行數來計算一行一行存成矩陣!但是這時候我又想到,剛好今天我這個檔案非常的小,行數也很短,如果我今天拿上萬行的數據執行,執行到死都執行不完!。
百思不得其解後,google了許久,在matlab官方網站看到了有人分享的寫法:
function [header, data] = hdrload(file)
% HDRLOAD Load data from an ASCII file containing a text header.
% [header, data] = HDRLOAD('filename.ext') reads a data file
% called 'filename.ext', which contains a text header. There
% is no default extension; any extensions must be explicitly
% supplied.
%
% The first output, HEADER, is the header information,
% returned as a text array.
% The second output, DATA, is the data matrix. This data
% matrix has the same dimensions as the data in the file, one
% row per line of ASCII data in the file. If the data is not
% regularly spaced (i.e., each line of ASCII data does not
% contain the same number of points), the data is returned as
% a column vector.
%
% Limitations: No line of the text header can begin with
% a number. Only one header and data set will be read,
% and the header must come before the data.
%
% See also LOAD, SAVE, SPCONVERT, FSCANF, FPRINTF, STR2MAT.
% See also the IOFUN directory.
% check number and type of arguments
if nargin < 1
error('Function requires one input argument');
elseif ~isstr(file)
error('Input must be a string representing a filename');
end
% Open the file. If this returns a -1, we did not open the file
% successfully.
fid = fopen(file);
if fid==-1
error('File not found or permission denied');
end
% Initialize loop variables
% We store the number of lines in the header, and the maximum
% length of any one line in the header. These are used later
% in assigning the 'header' output variable.
no_lines = 0;
max_line = 0;
% We also store the number of columns in the data we read. This
% way we can compute the size of the output based on the number
% of columns and the total number of data points.
ncols = 0;
% Finally, we initialize the data to [].
data = [];
% Start processing.
line = fgetl(fid);
if ~isstr(line)
disp('Warning: file contains no header and no data')
end;
[data, ncols, errmsg, nxtindex] = sscanf(line, '%f');
% One slight problem, pointed out by Peter vanderWal: If the
% first character of the line is 'e', then this will scan as
% 0.00e+00. We can trap this case specifically by using the
% 'next index' output: in the case of a stripped 'e' the next
% index is one, indicating zero characters read. See the help
% entry for 'sscanf' for more information on this output
% parameter. We loop through the file one line at a time until
% we find some data. After that point we stop checking for
% header information. This part of the program takes most of the
% processing time, because fgetl is relatively slow (compared to
% fscanf, which we will use later).
while isempty(data)|(nxtindex==1)
no_lines = no_lines+1;
max_line = max([max_line, length(line)]);
% Create unique variable to hold this line of text information.
% Store the last-read line in this variable.
eval(['line', num2str(no_lines), '=line;']);
line = fgetl(fid);
if ~isstr(line)
disp('Warning: file contains no data')
break
end;
[data, ncols, errmsg, nxtindex] = sscanf(line, '%f');
end % while
% Now that we have read in the first line of data, we can skip
% the processing that stores header information, and just read
% in the rest of the data.
data = [data; fscanf(fid, '%f')];
fclose(fid);
% Create header output from line information. The number of lines
% and the maximum line length are stored explicitly, and each
% line is stored in a unique variable using the 'eval' statement
% within the loop. Note that, if we knew a priori that the
% headers were 10 lines or less, we could use the STR2MAT
% function and save some work. First, initialize the header to an
% array of spaces.
header = setstr(' '*ones(no_lines, max_line));
for i = 1:no_lines
varname = ['line' num2str(i)];
% Note that we only assign this line variable to a subset of
% this row of the header array. We thus ensure that the matrix
% sizes in the assignment are equal. We also consider blank
% header lines using the following IF statement.
if eval(['length(' varname ')~=0'])
eval(['header(i, 1:length(' varname ')) = ' varname ';']);
end
end % for
% Resize output data, based on the number of columns (as returned
% from the sscanf of the first line of data) and the total number
% of data elements. Since the data was read in row-wise, and
% MATLAB stores data in columnwise format, we have to reverse the
% size arguments and then transpose the data. If we read in
% irregularly spaced data, then the division we are about to do
% will not work. Therefore, we will trap the error with an EVAL
% call; if the reshape fails, we will just return the data as is.
eval('data = reshape(data, ncols, length(data)/ncols)'';', '');
簡單的說,這個程式先一行一行判斷是否為string(if ~isstr(line)),然後在以data = [data; fscanf(fid, '%f')];讀入數值資料,並且會以[data, ncols, errmsg, nxtindex] = sscanf(line, '%f');(其中line是先讀入一行)去看ncols。
最後再把讀入的數值data資料用reshape的方式(data = reshape(data, ncols, length(data)/ncols);)完成。速率的確加快許多。
如題,最近在研究FreeMat和Scilab兩個免費又和matlab相似的軟體(應該說是clone)
matlab中的textread對於我讀大量數據的時候非常方便,自動可以存成矩陣,剛剛google了一下,發現scilab中的fscanfMat指令有相同功能。
不過現在美中不足的是,scilab介面改由java製成,plot指令居然會造成crash,哇哩勒!連plot都不能用那還搞啥東東!?於是只好將回version4使用!(難怪下載的時候發現scilab怎麼變得如此肥!)
matlab中的textread對於我讀大量數據的時候非常方便,自動可以存成矩陣,剛剛google了一下,發現scilab中的fscanfMat指令有相同功能。
不過現在美中不足的是,scilab介面改由java製成,plot指令居然會造成crash,哇哩勒!連plot都不能用那還搞啥東東!?於是只好將回version4使用!(難怪下載的時候發現scilab怎麼變得如此肥!)
訂閱:
文章 (Atom)

