2012-06-26 30 views
-1

嗨我導入Excel數據到MATLAB中,這是一個約200米名稱的列表,每個約有28行。
問題在於,每個方向都有一個副本用於其他方向,其中相同的儀表名稱後面有'x'我怎麼能在他們後面用'x'來消除名字?

有沒有人有任何想法,我怎麼能消除這些與'x'事後?
以下是導入數據我的代碼的一部分: 清除所有

fid=fopen('sue1.csv'); % Open the file sue1.csv and read it all and put it into an array 
data = textscan(fid,'%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s','Delimiter',',','CollectOutput',1); 
fclose(fid) 

j = 1; k = 1; % j - turbine number, k - date number 

for i = 1:length(data{1,1}) % Run through all the data 
    if strcmp(data{1,1}(i),'') == 0 

     meterold{j}(k,:) = data{1,1}(i,:); 
%   if strcmp(data{1,1}(i),'MeterName') == 0 
%    nummeter{j}(k,:) = str2num(data{1,1}(i,3:end)); 
%   end 
     k = k + 1; 

    else 
     % These commands are followed in the strings match (empty line) 
     k = 1; % Reset the day counter as we're back to the beginning 
     j = j + 1; % Add one to the meter counter as we're now looking at 
     % a new turbine 
    end 
end 
+1

問題是沒有數據(或至少一個樣本)令人困惑。我只能說,如果你正在閱讀CSV格式,爲什麼不使用'csvread'? – 2012-06-26 09:03:19

+0

請正確格式化您的代碼片段,這將使我們更容易欣賞。 –

回答

0

很難用一個樣本來回答這個問題,但也許這將幫助。

如果字符串中的「x」這樣的結尾你可以告訴:

M = [1 2 3; 4 5 6; 7 8 9] 
M(2,:) = []; 

希望你能組合這些:

if myString(end) == 'x' 

,你可以從這樣的矩陣刪除行兩個來解決你的問題。

+0

只需要在forloop中刪除像這樣的行的警告,您應該從末尾開始循環,否則您將跳過直接刪除行後直接檢查任何行。 – Dan

+0

這將是行刪除,它在單元格矩陣上工作。試試這個:M = cell(3); M(2,:) = [];在我的Matlab上正常工作。 – Dan

+0

我不知道沒有看到數據,但OP想要有條件地刪除行。所以這是刪除一行的一種方法。 – Dan

相關問題