フィルターのクリア

How do I associate specific values to specific verbiage?

9 ビュー (過去 30 日間)
Brad
Brad 2013 年 10 月 9 日
コメント済み: Azzi Abdelmalek 2013 年 10 月 9 日
I've got 2 arrays: A = [1; 2; 3; 1; 2; 3]; and B = [ ];
I need array B to contain [Lost; Found; Unk; Lost; Found; Unk] based on the values found in A.
I'm using the find function to locate the indices of the values 1, 2, and 3. But I'm not sure what to do next.
Any ideas are appreciated. Thanks.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 9 日
A = [1; 2; 3; 1; 2; 3]
v={'Lost'; 'Found'; 'Unk'}
B=v(A)
  4 件のコメント
Brad
Brad 2013 年 10 月 9 日
Sorry Azzi.
What if A = [1; 11; 3; 1; 2; 3; 55; 1; 53; 29] ?
How would I associate 'Lost', 'Found', 'Unk' with 1,2, and 3?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 9 日
Something is missing in your question

サインインしてコメントする。

その他の回答 (1 件)

Karen
Karen 2024 年 9 月 23 日 6:25
To achieve the desired transformation of array A into array B, you can use a combination of the find function and logical indexing in MATLAB. Here’s a step-by-step solution:
matlab
Copy code
A = [1; 2; 3; 1; 2; 3];
B = strings(size(A)); % Initialize B as a string array of the same size as A
% Find indices for each value in A
index1 = find(A == 1);
index2 = find(A == 2);
index3 = find(A == 3);
% Assign the corresponding strings to the indices
B(index1) = "Lost";
B(index2) = "Found";
B(index3) = "Unk";
% Display the result
disp(B);
Here’s how it works:
  1. Initialization: We initialize B as a string array with the same size as A.
  2. Finding Indices: Using the find function, we locate the indices of elements in A that are equal to 1, 2, and 3.
  3. Assigning Values: We assign the corresponding string values ("Lost", "Found", "Unk") to the respective indices in B.
  4. Displaying Result: Finally, we display the resulting array B.
The output will be:
matlab
Copy code
6×1 string array
"Lost"
"Found"
"Unk"
"Lost"
"Found"
"Unk"
If you're looking for expert assistance with MATLAB assignments, whether for similar problems or more complex tasks, check out MATLAB Assignment Experts. They offer professional help with guaranteed quality and timely delivery.
Why Choose MATLAB Assignment Experts?
  • Expert MATLAB Programmers: Skilled professionals to handle all your MATLAB needs.
  • Customized Solutions: Tailored to your specific assignment requirements.
  • On-Time Delivery: Ensuring you meet your deadlines.
  • Affordable Rates: Student-friendly prices.
  • 24/7 Support: Round-the-clock assistance for any queries.
For more details, visit www.matlabassignmentexperts.com, email at info@matlabassignmentexperts.com, or WhatsApp at +1 (315) 557-6473. Don't let MATLAB assignments hold you back. Get expert help now!

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by