Im trying to add only a few elements from 1 big array too a smaller array, im using a if statement to get the data i want, then im trying to add those can someone help :D

2 次查看(过去 30 天)
[~, ~, activeBatch] = xlsread('G:\Vision\Vision oversigt.xlsx','Color Management','Y3:Y966');
for i=1:numel(activeBatch)
if contains(activeBatch{i},'ActiveX VT_ERROR:')
activeBatch{i,2} = 0; %delete
else
Batct = activeBatch{i};
activeBatch{i,2} = 1;
end

回答(1 个)

Rohit Kulkarni
Rohit Kulkarni 2023-9-4
Hi Mark,
Based on my understanding, it seems like you are attempting to add specific elements from one array to another based on a certain condition. However, I am unable to fully comprehend your code. Here is an example that illustrates a similar condition:
In the example provided below, an element from “array1” will be added to “concatenatedArray” if it contains the substring "an". Conversely, if the element does not contain "an", an element from “array2” will be added.
%Sample arrays
array1 = ["apple", "banana", "orange"];
array2 = ["grape", "kiwi", "mango"];
% Initialize the concatenated array
concatenatedArray = [];
% Loop through the elements of array1
for i = 1:length(array1)
% Check if array1 element contains "an"
if contains(array1(i), "an")
% Concatenate the element from array1 to the concatenatedArray
concatenatedArray = [concatenatedArray, array1(i)];
else
% Concatenate the element from array2 to the concatenatedArray
concatenatedArray = [concatenatedArray, array2(i)];
end
end
% Display the concatenated array
disp(concatenatedArray);
You can modify the above code according to your specifications.
Also, it is recommended to use “readtable” instead of “xlsread” in your code.
Please refer to the documentation provided below for more information on the “readtable” function. https://in.mathworks.com/help/matlab/ref/readtable.html
Hope the example provided helps!

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by