我有一个包含9列的txt文件,最后一列是0或1。我想根据最后一列的值将它们保存到其他txt文件中。如何使用matlab做到这一点?
txt文件
43 34 6 8 2 6 2 3 0
23 54 2 5 8 2 61 6 1
46 4 6 8 23 6 2 3 0
3 5 2 75 48 23 1 6 0
3 54 23 5 58 2 1 6 1
46 4 67 8 3 6 24 23 0
32 5 2 75 98 23 1 6 1
答案 0 :(得分:0)
我假设您知道如何将矩阵保存到文件,但不知道拆分矩阵的方法。
在这里,我只提供一种解决方案,可以帮助您根据最后一列拆分矩阵:
$('#btnEditImageSave').unbind().click(function (event) {
$('#progressBardiv').css('width', '0');
$('.progressBardiv').text('');
if (uploadedfiles.length > 0 && deleteFiles.length == 0) {
if (editStoredFiles.length > 0) {
var files = new FormData();
for (var i = 0; i < editStoredFiles.length; i++) {
if (editStoredFiles[i].size > 0) {
files.append(editStoredFiles[i].name, editStoredFiles[i]);
}
}
uploadedfiles = [];
files.append('SerialNumber', editSerialNumber);
$.ajax({
type: "POST",
url: productionBaseUrl + '/Home/UploadDockingStationFiles',
data: files,
contentType: false,
processData: false,
async: true,
complete: function () {
uploadedfiles = [];
$('#editfileupload').val();
$.ajax({
type: "POST",
url: cloudServerUrl + "/api/dockstation/updatefiledisplaytimer",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
SerialNumber: $('#ddlEditDockingStationSerialNumber').val(),
FileSpinTimer: $('#txtEditTimer').val(),
IsHDMIUpdate: isHDMIUpdate
}),
/*----My Progress Bar code----*/
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (event) {
if (event.lengthComputable) {
var percentComplete = event.loaded / event.total;
percentComplete = parseInt(percentComplete * 100);
$('#progressBardiv').text(percentComplete + '%');
$('#progressBardiv').css('width', percentComplete + '%');
}
}, false);
return xhr;
},
complete: function () {
$('#loading-popup').hide();
$('#divEditDockingStationImages').dialog("close");
$.popup('<pre>Message</pre>', "Image Configuration Updated Successfully.", 'OK');
return false;
}
});
}
});
}
}
else {
$('#loading-popup').hide();
$.popup('<pre>Message</pre>', "Please Select a File.", 'OK');
return false;
}
}
<div class="progress">
<div id="progressBardiv" class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="">
<span class="sr-only"></span>
</div>
</div>
然后,您可以将矩阵% ending with 0 in each row
m0 = m(find(m(:,end)==0),:);
>> m0
m0 =
43 34 6 8 2 6 2 3 0
46 4 6 8 23 6 2 3 0
3 5 2 75 48 23 1 6 0
46 4 67 8 3 6 24 23 0
% ending with 1 in each row
m1 = m(find(m(:,end)),:);
>> m1
m1 =
23 54 2 5 8 2 61 6 1
3 54 23 5 58 2 1 6 1
32 5 2 75 98 23 1 6 1
和m0
保存在不同的.txt文件中,例如m1
和dlmwrite('m0.txt',m0)
数据
dlmwrite('m1.txt',m1)