我找到了PSPP *的解決方案,這對於SPSS也可能有用。這個想法很簡單 - 按照你在問題中描述的內容,但是採用自動化的方式。如果你想要的數值,而不是標貼
GET FILE = 'your_SPSS_file_with_full_path.sav'
save translate
/outfile = 'your_resulted_CSV_file_with_full_path.csv'
/type = CSV
/REPLACE
/FIELDNAMES
/CELLS=LABELS.
寫CELLS=VALUES
:
開始通過編寫腳本文件SPSS(以下是PSPP,但應該是非常相似的SPSS)。
保存這個文件(假設它叫做spss2csv.sps)。
在Matlab中寫:
sps_file_name = 'full_path\spss2csv.sps';
% replace the path below with the path for SPSS:
command = ['"C:\Program Files\PSPP\bin\pspp.exe" ' sps_file_name];
system(command)
這將生成一個.csv文件,您可以通過xlsread
或使用import tool導入到Matlab的兩種:
uiimport(your_resulted_CSV_file_with_full_path.csv)
這個工具可以導入混合數據並生成腳本,以便下次自動完成。
對於相反的方向(Matlab來SPSS)看看這些意見,以文件交換:
- export data to spss。
- save4spss。
* PSPP是免費的,作品非常快,因此,如果您不能執行此在SPSS只要下載。
這裏是你可以在Matlab如果你安裝了PSPP,沒有走出Matlab的在所有使用功能:
function import_sav(sav_file,labels)
% Opens the import tool for importins a sav file
% 'sav_file' is the name of the SPSS\PSPP file to import
% 'labels' is a logical that if true then the file is imported using the
% labels and not the numeric values. Default is TRUE.
if nargin<2
labels = true;
end
[p,csv_file] = fileparts(sav_file);
if isempty(p), p = cd; end
sps_file = [p '\convert2csv.sps'];
% sav_file = 'C:\Users\Eyal\Dropbox\MATLAB\atid\result.sav';
csv_file = [p '\' csv_file '.csv'];
fid = fopen(sps_file,'w');
fprintf(fid,'GET FILE = ''%s''\n',sav_file);
fprintf(fid,'save translate\n');
fprintf(fid,'\t\t/outfile = ''%s''\n',csv_file);
fprintf(fid,'\t\t/type = CSV\n');
fprintf(fid,'\t\t/REPLACE\n');
fprintf(fid,'\t\t/FIELDNAMES\n');
if labels
fprintf(fid,'\t\t/CELLS=LABELS.\n');
else
fprintf(fid,'\t\t/CELLS=VALUES.\n');
end
fclose(fid);
command = ['"C:\Program Files\PSPP\bin\pspp.exe" ' sps_file];
system(command)
uiimport(csv_file)
end
這將自動打開數據導入工具針對的.sav調用函數時輸入的文件:import_sav('my_file.sav',1)
。
Matlab確實[支持ODBC](https://www.mathworks.com/help/database/ug/importing-data-from-databases-into-matlab.html),但OP將需要[數據庫工具箱] (https://www.mathworks.com/help/database/index.html)。另外,我不確定此選項是否在SPSS的核心許可下打開。 – EBH
我認爲驅動程序是免費的,可能包含在基本產品許可的數據訪問包中。 – JKP