You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to compare two lists
Accepted Answer
19 Comments
"Umer: you want to output zero if a is not a member of b, but this answer does not do that."
Huh?
>> b =[1 2 3 4 5 ]
b =
1 2 3 4 5
>> a = [1 2 7]
a =
1 2 7
>> a .* ismember(a,b)
ans =
1 2 0
mask = ~ismember(a, b); c = a;
then
c(mask) = 2; %change the missing items to the fixed value 2
or
c(mask) = a(mask) - 1; %change the missing items to one less than their original value
- if the datatypes are uint8, int16, or int32, then the code assumes you knew what you were doing with the range of values and leaves them completely unchanged
- if the range of values is -1 to +1 then the code assumes you knew what you were doing with the range of values and leaves them unchanged, but alters the datatype to double. The cases where the data type could end up altered are single() that are in the right range, and int64(). The way the code is set up cannot affect the other integer data types
- if the values are all non-negative, then the code assumes you knew what you were doing about the lower end of the values, and rescales [0 max(c)] to [-1 +1] . So, for example, your range of values happened to be 30000 to 50000 then this will be mapped first to [30000/50000, 50000/50000] and then the [0 1] range would be mapped to [-1 +1] so the [30000/50000, 50000/50000] would end up mapping to [1/5 1]. It would also have been entirely reasonable to instead map [min(c) max(c)] to [-1 +1]: in the absence of information from you about what should be done, a decision had to be made
- otherwise, in the case where there was a mix of positive and negative values but the range was outside [-1 +1], the code scales [min(c) max(c)] to [-1 +1]
More Answers (0)
See Also
Categories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)