フィルターのクリア

Replacing indexed row with string

1 回表示 (過去 30 日間)
Cside
Cside 2020 年 12 月 28 日
回答済み: Mathieu NOE 2020 年 12 月 28 日
Hi, I have a matrix that contains all the row numbers and I would like these row numbers to be replaced by the string 'a' in the empty vector test. For the row numbers not indexed, I would like them to be replaced with 'b'.
The code does not seem to allow replacement with a string. Do let me know how to solve this thanks!
test(find(lv1),:) = 'a'

回答 (1 件)

Mathieu NOE
Mathieu NOE 2020 年 12 月 28 日
hello
see example below
hope it helps
test = (1:30);
test(3:15) = 0; % create some zeroes in the vector
%% main code %%
test = test(:); % makes test always vertical
tol = eps;
ind1 = find(abs(test) <= tol); % zero elements
ind2 = find(abs(test) > tol); % non zero elements
test_str =num2str(test); % convert numerical to string
[m,n] = size(test_str);
for ci = 1:length(ind1) % zero elements
test_str(ind1(ci),:) = [blanks(n-1) 'a'];
end
for ci = 1:length(ind2) % non zero elements
test_str(ind2(ci),:) = [blanks(n-1) 'b'];
end

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by